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 on my TextView:
TextView text = (TextView) vi.findViewById(R.id.menutext);
text.setText(itemnames[position]);//comes from database append to text view
Now I want to define a setOnLongClickListener to convert it into a EditText.
text.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
String edititemname=itemnames[position];
System.out.println(edititemname);
return true;
}
});
edititemname
holds which item was pressed in a long click. I want to fill the same information into the EdiText. Please help me.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With