Android地图autocompletetextview

时间:2012-10-24 06:06:57

标签: android map autocompletetextview

我想在我的Android应用程序中设置 autoCompleteTextView ,当我在Google地图的 autoCompleteTextView 中输入字符时,它会显示所有位置。如何在我的应用中添加该类型的 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"
 };

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

请给我一个解决方案..

1 个答案:

答案 0 :(得分: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();

    }
});