I am developing an application where the user can edit the data in the ListView
. I want to have an EditText
inside that ListView, this edittext should behave like TextView but when the user clicks it it should look like EditText
, How can i achieve this functionality?
Actually the EditText inside the ListView looks ugly & i want that the EditText should look like a TextView bydefault but when the user try to Edit the data then it should look like the EditText.
I hope that my question is clear if not please ask.
Use selector for EditText to create different states. If it is in idle state give normal color drawable as background and if it is focussed use a 9 patch PNG drawable which resembles real EditText background.
I hope it may help you. If you don't know how to use selector, feel free to ask me.
Sample ScreenShots
I am using 1 TextVuew and 2 EditText views in my app, check below screen shots to know how the EditText will look like according to your requirements. If you like them and it is actually required then i post code here.
Initial Screen
While taking Input for 1st EditText
While taking Input for 2nd EditText
well, I would recommend to use textview.. and when click on it it will swap to editText(add View /removeView ) in parent.. and when focus changes it will reverted back to textview with new changes .. second solution to use popup dialog for editing purpose with done button to submit and back to get back to list. third solution to change style of editText with :
Use setCursorVisible(false) to hide the cursor and onclick of edittext setCursorVisible(true). this, also set background color to white of edittext
The below files I used in my app.
main.xml in layout folder
myshape.xml in drawable folder
bg.xml in drawable folder
Java file
You can prompt user To input with an AlertDialog.