AutoCompleteTextView在下拉列表中显示重复的建议

时间:2015-06-06 06:12:39

标签: android duplicates autocompletetextview

AutoCompleteTextView在建议的下拉列表中显示重复项。

请告诉我的代码是否有任何问题。感谢。

Øresund
Åse
Alfa

其中CustomAutoCompleteTextView是一个下面的类,它返回从下拉列表中选择时显示的电子邮件。

CustomAutoCompleteTextView email_id; 
email_id = (CustomAutoCompleteTextView) v.findViewById(R.id.etUserId);

// Each row in the list stores  name, email
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();

for (int i = 0; i < jar_contacts.length(); i ++) {
    HashMap<String, String> hm = new HashMap<String,String>();
    hm.put(
       "txt",
       jar_contacts.optJSONObject(i).optString("first_name")
           + " "
           + jar_contacts.optJSONObject(i).optString("surname")
    );
    //hm.put("flag", Integer.toString(flags[i]) );                         

    hm.put(
        "email",
        jar_contacts.optJSONObject(i).optString("user_id_email")
    );
    aList.add(hm);
}

// Keys used in Hashmap
String[] from = { "txt", "email"};

// Ids of views in listview_layout
int[] to = { R.id.tName_auto,R.id.t_email_auto };

// Instantiating an adapter to store each items
SimpleAdapter adapter = new SimpleAdapter(
    ct, aList, R.layout.autocomplete_create_msg, from, to
); 

// Defining an itemclick event listener for the autocompletetextview
OnItemClickListener itemClickListener = new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id {
        /** Each item in the adapter is a HashMap object.
        *  So this statement creates the currently clicked hashmap object
        * */
        HashMap<String, String> hm =
            (HashMap<String, String>) arg0.getAdapter().getItem(position);
    }
};

/** Setting the itemclick event listener */
email_id.setOnItemClickListener(itemClickListener);

/** Setting the adapter to the listView */
email_id.setAdapter(adapter);

1 个答案:

答案 0 :(得分:0)

{email_idsetDuplicateParentStateEnabled(false); }