1

I am beginning with multiautocompletetextview. I use ArrayAdapter. Now, when I choose any country, I want get their code and name. How do I do it? I need to help.

This is my code. Main Activity and class Country

public class Country {
    String code;
    String name;

    public Country(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayList<Country> countries = new ArrayList<>();
        countries.add(new Country("1", "Viet Nam"));
        countries.add(new Country("2", "Lao"));
        countries.add(new Country("3", "Campuchia"));
        countries.add(new Country("4", "America"));
        countries.add(new Country("5", "Boom Boom"));
        ArrayAdapter<Country> adapter = new ArrayAdapter<Country>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, countries);
        MultiAutoCompleteTextView multiAutoCompleteTextView = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView);
        multiAutoCompleteTextView.setAdapter(adapter);
        multiAutoCompleteTextView.setThreshold(1);
        multiAutoCompleteTextView.setDropDownWidth(300);
        multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    }
Tung Tran
  • 2,885
  • 2
  • 17
  • 24
  • I think you can refer to my answer at http://stackoverflow.com/questions/33047156/how-to-create-custom-baseadapter-for-autocompletetextview/33049491#33049491, for AutoCompleteTextView, however, IMO, you can apply for your MultiAutoCompleteTextView – BNK Dec 12 '15 at 07:47

0 Answers0