How to convert a TextView to EditText in android?

后端 未结 3 1732
一整个雨季
一整个雨季 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"

提交回复
热议问题