2

我想在我的 android 应用程序中设置autoCompleteTextView,当我在autoCompleteTextView中输入字符时,它会显示所有位置,例如 Google map 。如何在我的应用程序中添加这种类型的autoCompleteTextView。我目前正在使用此代码:

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView)
            findViewById(R.id.autoCompleteTextView);
    textView.setAdapter(adapter);
    .
    .


    private static final String[] COUNTRIES = new String[] {
     "Belgium", "France", "Italy", "Germany", "Spain"
 };

但是是显示字符串数组中的位置。

请给我一个解决方案..

4

1 回答 1

0
 autoCompleteTextView=findViewById(R.id.autoCompleteTextViewID);
employeeNames  = new ArrayList<String>();

// getdata & store in dataList

dataAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, employeeNames );
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
autoCompleteTextView.setThreshold(1);
autoCompleteTextView.setAdapter(dataAdapter);

autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        String selectedStr  = parent.getItemAtPosition(position).toString();

    }
});
于 2018-07-13T10:07:12.713 回答