2010-10-11 13 views
1

J'ai besoin d'implémenter AutoCompeleteTextView comme application de messagerie par défaut. Je l'ai déjà implémenté comme donné en première image. Maintenant, je veux exactement comme donné dans la deuxième image.AutoCompeleteTextView comme Android Application de messagerie par défaut

alt text

L'extrait de code suivant J'utilise:

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

et le fichier de mise en page est comme ci-dessous: 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> 

Maintenant, s'il vous plaît quelqu'un pourrait suggérer moi une meilleure façon de mettre en œuvre la fonctionnalité.

+0

Jetez un oeil ici: http://thinkandroid.wordpress.com/2010/02/08/writing-your-own-autocompletetextview /. – Edi

Répondre

2

Enfin j'ai ce que je cherchais exactement.

Le lien est ici:

Custom AutoCompleteTextView for Android

+3

Vous devriez vraiment essayer de mettre à jour cette réponse pour inclure des informations pertinentes du lien que vous avez fourni. – animuson

+0

Salut Vikas, vous devriez également mettre à jour votre autre réponse [ici] (http://stackoverflow.com/a/4759429/552792) ainsi. Vous faites passer les gens à travers beaucoup de liens afin de trouver l'information, et sur Stack Overflow, nous préférons que les réponses soient largement autonomes. J'espère que cela t'aides! :) – jmort253