There is in the application View, which is built on the basis of xml and css - a tree, and if you pull the representation method for the top element of the tree, then it draws itself by nodes and lists each of which represents a ViewGroup or View, respectively. For label tags in markup, a TextView is built, for ImageButton, an ImageView is built, for containers, as a rule, RelativeLayout. As with TextView, this field can be editable. I did not consider EditText, since the field should look like the simplest text, and EditText due to the peculiarities of its markup is simply cut on the final image of the template due to the fact that its height is almost twice the height of its text. When I create a View based on the element representing the text, I do the following
@Override public View representation(Context context, CssStyleSheet cssStyleSheet, Template.Manifest manifest) { label = new Text(context); label.setHint(defaultText); cssStyleSheet.applyStyle(label, id, cssClass); if (editable) { label.setFocusable(true); label.setCursorVisible(true); label.setClickable(true); label.setEnabled(true); label.setInputType(InputType.TYPE_CLASS_TEXT); label.setOnClickListener(v -> { label.setFocusableInTouchMode(true); label.requestFocus(); }); label.setBackgroundColor(Color.TRANSPARENT); } else { label.setFocusable(false); label.setFocusableInTouchMode(false); // user touches widget on phone with touch screen label.setClickable(false); } return label; } that is, I provide TextView with all the necessary parameters for using it as an input field. However, when I enter text, I see a change only at the beginning of the input, that is, if I enter "fgdlhfgld" there, I see only "f" or maximum "fg" in the TextView, after which no changes occur, which I did not enter. If I reopen the fragment on which I have this view, then the view is recalculated (not rendered, it is redrawn, since representation is called only if the global View is == null), and I see all the changes made to the text, but if I’ve If I click on this field on the device and enter the text, I will not see any external changes until I reopen the fragment from the View.
Is there any parameter for TextView that will update it during text entry? I tried to add OnKeyListener where I did
label.setText(label.getText()) which did not lead to the result and added a TextWatcher in which I tried to indent the incoming string into a label, but it turned out to be a recursion, since the TextWatcher methods are called inside setText.