How to convert a TextView to EditText in android?

后端 未结 3 1759
一整个雨季
一整个雨季 2021-01-05 08:02

I am fetching the data from a database and I am appending it to a TextView. When I do long click on TextView I want to convert it to an EditText. This is how I set the data

3条回答
  •  我在风中等你
    2021-01-05 08:54

    As far as I know you can't convert one to another. What you can is: Have a TextView and an EditText created in xml. EditText is hidden when TextView is showing. Then, on your listener to the onCLick you can:

    text.setVisibility(View.GONE); 
    editText.setVisibility(View.VISIBLE);
    editText.setText(edititemname);
    

    The editText variable can be defined where you define the text. You have to use the findViewById.

提交回复
热议问题