0

I needed a recipient EditText in my app, so, I used this TokenAutoComplete library to do the same. However, I am having a few problem with this.

  1. When I type a name, a drop down list comes. I want to give a custom layout to this drop down list. How can I do it? Currently I am showing just text here using toString method.

Below is the code.

@Override
public String toString() { return mContactFirstName }

I want to show here name and photo together. How can I do it?

  1. Changing the layout for selected token. When the token is not selected/default, the token's background is white and it's text color is black. On the other hand, if the token is selected, the token's background should be black and it's text color should be white colored. I used a selector xml to change the token's background, however, I don't know how to change the text's color.

The selector xml is working perfectly fine and the background is changing when the token is selected and unselected, but, the text's color remains same.

I used below setSelected() method to change the text's color. But it's not working.

    @Override
public void setSelected(boolean selected) {
    super.setSelected(selected);
    TextView tv = (TextView) findViewById(R.id.token_name);
    if(selected) {
        tv.setTextColor(Color.WHITE);
    } else {
        tv.setTextColor(Color.BLACK);
    }
}

Please help me out.

Nitesh Kumar
  • 5,370
  • 5
  • 37
  • 54

1 Answers1

1

In the example that TokenAutoComplete library provides you can see that the ContactsCompletionView provides setAdapter method. You can set your custom adapter there, any adapter that extends BaseAdapter will do.

so you just do like this:

myAdapter = new MyCustomAdapter(); // extending BaseAdapter
completionView.setAdapter(myAdapter);

in case of a custom adapter there are plenty of resources on the web, but basically in getView method you create custom view by inflatind it from xml. in the xml you can define the layout you desire (image, text, whatever...).

for more info refer to this question: Custom Adapter for List View

Community
  • 1
  • 1
RafalManka
  • 366
  • 5
  • 14
  • I think you haven't read the question carefully. I am not asking for a custom layout in a listview. I needed a custom layout of the drop down list. – Nitesh Kumar Jul 30 '14 at 06:48
  • Doing a custom layout of the list is pretty tricky. If you just want to customize the list entries, setting a custom adapter that overrides the adapter getView methods will let you do custom layout for the entries – Marshall Weir Jun 04 '15 at 18:37