Reputation: 149
I've a ListView that displays a single button and a single EditText in each ListView row.
I'm using the ViewHolder pattern in my ArrayAdapter so all the buttons share a single OnClickListener. Picking up the button click is easy because onClick(View view) in my OnClickListener gives me the view (and I use getTag() to get my model object).
I can't figure out how to have a single TextWatcher to get the changed text, because there's no view parameter in TextWatcher onTextChanged() callback. Any help appreciated!
Upvotes: 1
Views: 3471
Reputation: 19290
The trick is to create a generic TextWatcher class. Then, each instance you create should be passed a reference of the View it will be placed into.
Example: https://stackoverflow.com/a/6172024/560600
Upvotes: 1
Reputation: 1750
For get the value of the EditText, in the Listener of the button i worked so:
viewHolder.button.setTag(viewHolder.YourEditText);
viewHolder.button.setOnClickListener(new OnClickListener()){
@Override
public void onClick(View v) {
int p = position;
EditText edit = (EditText) v.getTag();
String val = edit.getEditableText().toString();
//do what you want with the value...
}
}
Where position
is public View getView(final int position, View convertView, ViewGroup parent){...
If you'll need, i can post the entire AdapterClass.
Upvotes: 0