How to convert a TextView to EditText in android?

后端 未结 3 1731
一整个雨季
一整个雨季 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:36

    I have Tested and it is Working :

        final EditText et=(EditText)findViewById(R.id.editText1);
        final TextView tv=(TextView)findViewById(R.id.txt);
    
    
        tv.setOnLongClickListener(new OnLongClickListener() {
    
            @Override
            public boolean onLongClick(View v) {
                // TODO Auto-generated method stub
                tv.setVisibility(4);
                final EditText et2=(EditText)findViewById(R.id.editText2);
                et2.setVisibility(1);                       
                return false;
    
            }
        });
    

    Just Keep EditText as android:visibility="gone"

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-05 08:55

    yes you can for that create a edittext just behind the textview in long press of textView hide textView and show editext as you done hide edittext and make visible textView

    as you make invisible textview set edittext text to textview text

    0 讨论(0)
提交回复
热议问题