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
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"
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
.
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