How do i access a edittext box on a listview row
I have a list vie开发者_StackOverflow社区w with edittext on each row. If a user clicks on a rowhowcan i access that particular edittext?
You should initialize EditText
's onClickListener()
inside your adapter's getView()
method, right where you inflate this EditText
. Hope this helps.
If the EditText
boxes were created during runtime, you can use setId(int)
when creating them. Then, through your ListView
, you can use findViewById(int id)
to retrieve it in the future. So the full call would be like EditText myEditText = (EditText) myListView.findViewById(1)
would retrieve the box who's ID you set to 1
.
If you create them through XML, then you can assign the ID to them in the xml that you can easily remember. Afterwards, you can use findViewById(int id)
the same way as before but use the ID references in the generated R file.
I want you to use listAdapter class.
You must make your own class which extends the BaseAdapter class.
Then make a listItem class which contains a EditText Control.
And deal events of EditText in the class.
Then you must add the class as the arrays of class into the listAdapter class.
And override the getView function of BaseAdapter class.
精彩评论