How to make TextView editable with the click of a button?

I have an application that displays specific content from a database and allows users to edit it. I have an activity that displays these details in some text views. Now at the bottom of the screen there is an "EDIT" button. When this button is pressed, I want to make editable text (which is initially read-only) so that the database can be updated. In addition, I want the "EDIT" button to turn into the "SAVE" button. I understand that I can simply use other activities for this, but is there a way to do this at the same time?

-3
source share
2 answers

EditText is a TextView that it can make a TextView better [

so suppose you have a TextView

  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="i am a text" android:textColor="#243b03" /> 

and you want it to be edited with the click of a button; in your onclick add this

  TextView.setCursorVisible(true); TextView.setFocusableInTouchMode(true); TextView.setInputType(InputType.TYPE_CLASS_TEXT); TextView.requestFocus(); //to trigger the soft input 

they are not static, but I made it static so that you know what methods of the view object are. About your button, after entering text, you will change the text to "done" or something else, Button will continue from TextView , so treat it as if it were - study on TextWatcher

+2
source

You would be better off switching the TextView to EditText and switching it with editText.setEnabled(boolean) to get the desired effect

0
source

Source: https://habr.com/ru/post/952587/


All Articles