1

私はmultiautocompletetextviewから始めています。私はArrayAdapterを使用します。今、国を選択すると、そのコードと名前を取得したいと思います。どうすればいいのですか?私は助ける必要があります。

これは私のコードです。主な活動とクラス 国

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());

    }
4

0 に答える 0