0
我有一個AutoCompleteTextView,一個帶有TextView的ListView。我想將選中的文本項發送到Toast語句。下面是我的代碼,然後我main.xaml和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>
我沒有看到選擇當我從列表中選擇,以填補AutoCompleteText框。
在此先感謝。