AutoCompeleteTextView wie die Standard-Messaging-Anwendung von Android
Ich muss die AutoCompeleteTextView wie die Standard-Messaging-Anwendung implementieren. Ich habe es bereits implementiert, wie im ersten Bild angegeben. Jetzt möchte ich genau wie im zweiten Bild angegeben.
Das folgende Code-Snippet, das ich verwende:
Cursor cursor = this.getContentResolver().query(Phone.CONTENT_URI,
new String[] { Phone.DISPLAY_NAME, Phone.NUMBER }, null, null,
Phone.DISPLAY_NAME + " ASC");
startManagingCursor(cursor);
cursor.moveToFirst();
int i = 0;
do {
HashMap<String, String> map = new HashMap<String, String>();
map.put("No", cursor.getString(cursor.getColumnIndex(Phone.NUMBER))
.replace("-", ""));
map.put("Name",
cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME)));
list.add(map);
i++;
} while (cursor.moveToNext());
SimpleAdapter adapter = new SimpleAdapter(this, list,
R.layout.autocomplete, new String[] { "Name", "No" },
new int[] { R.id.name, R.id.number });
txt_mobile_no.setAdapter(adapter);
txt_mobile_no
.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
und die Layoutdatei ist wie folgt: autocomplete.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name"
android:textSize="16dip"
android:layout_weight="1"
android:textColor="#000000"
android:paddingLeft="6dip"
android:paddingTop="10dip"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/number"
android:textSize="16dip"
android:layout_weight="1"
android:textColor="#000000" android:paddingTop="10dip"/>
</LinearLayout>
Jetzt könnte mir bitte jemand einen besseren Weg vorschlagen, um die Funktion zu implementieren.