1

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!

2
  • can you paste the code so that I can suggest where you need to change Commented Sep 4, 2013 at 6:50
  • for all the EditText u want to create a single textWatcher Commented Sep 4, 2013 at 6:55

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks - just what I was after. I ended up abandoning the EditText in ListView because of the world of pain focus problems stackoverflow.com/questions/2679948/… (as Joe said "just not idiomatic-Android UI design"). For now a dialog box is good enough and I circle back on this later!
Yes! I should have remembered trying that as well. ListViews are really great for letting you display a list of memory-intensive resources, since they manage garbage collection for you. However, when I need to focus on the elements, I'm forced to use a ScrollView.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.