2011-06-20 6 views
0

J'ai un AutoCompleteTextView, un ListView avec un TextView. Je souhaite envoyer l'élément de texte sélectionné à une instruction Toast. Ci-dessous mon code, suivi de mon main.xaml et item_list.xmlListView ItemClick MonoDroid

 String[] names = GetAllNames(db1.WritableDatabase); 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, names); 
     textView.Adapter = adapter; 


    ListView input1 = (ListView)FindViewById(Resource.Id.lview1); 

     input1.ItemClick += delegate(object sender, ItemEventArgs args) 
     { 
     // When clicked, show a toast with the TextView text 
     Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show(); 
     }; 

    /* main.xaml */ 

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <Button 
    android:id="@+id/MyButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Hello"/> 
    <AutoCompleteTextView android:id="@+id/autocompleteName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp"/> 
    <ListView 
    android:id="@+id/lview1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    </ListView> 
    </LinearLayout> 

    /* list_item.xml */ 

    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tview1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="test" 
    android:textSize="20sp" 
    > 
    </TextView> 

Je ne vois pas la sélection lorsque je choisis dans la liste pour remplir la boîte de AutoCompleteText.

Merci d'avance.

Répondre

0

Je sais que cet article est assez ancien, mais ce que je pense que vous voulez, c'est utiliser AutoCompleteTextView.ItemClick à la place. De même, vous n'avez pas besoin de ListView car la vue de texte a sa propre liste à sélectionner.