C# Monodroid:我如何用从SQL带来的数据表中的数据填充ListView?

C# Monodroid:我如何用从SQL带来的数据表中的数据填充ListView?,c#,android,visual-studio-2010,xamarin.android,C#,Android,Visual Studio 2010,Xamarin.android,我有一个DataTable,其中包含从SQL Server查询的名称。我想使用这些名称填充在.axml文件中创建的ListView。处理这个问题的最佳方法是什么?这就是我到目前为止所做的: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using An

我有一个DataTable,其中包含从SQL Server查询的名称。我想使用这些名称填充在.axml文件中创建的ListView。处理这个问题的最佳方法是什么?这就是我到目前为止所做的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Data;

namespace MonoAndroidApplication3
{
    [Activity(Label = "care sheet list test")]
    public class caresheetlist : ListActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            DAL d = new DAL("Data Source=.;Initial Catalog=reptitips;Integrated Security=True");
            DataTable tbl = d.FillAndReturn("select ReptileCommonName from reptiles order by ReptileCommonName", null, null, null);

            string[] reptileNames = new string[tbl.Rows.Count];

            for (int i = 0; i < reptileNames.Length; i++)
            {
                reptileNames[i] = tbl.Rows[i]["ReptileCommonName"].ToString();
            }


            ListAdapter = new ArrayAdapter<string>(this, Resource.Layout.listitem, reptileNames);

            ListView.TextFilterEnabled = true;

            ListView.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();
            };

            //AutoCompleteTextView textView1 = (AutoCompleteTextView)FindViewById(autoComplete1);
            //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, Resource.Layout.listitem, reptileNames);
        }
    }
}
以及.axml:

<?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="wrap_content"
    android:background="@drawable/bg"
    android:orientation="vertical" >

  <LinearLayout
      android:id="@+id/linearLayout2"
      android:layout_width="match_parent"
      android:layout_height="44dp"
      android:orientation="vertical" >

    <AutoCompleteTextView
        android:id="@+id/autoComplete1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="AutoCompleteTextView" >
    </AutoCompleteTextView>
  </LinearLayout>

  <LinearLayout
      android:id="@+id/linearLayout1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1" >

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

      <ListView
          android:id="@+id/listView1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1" >
      </ListView>

    </LinearLayout>

  </LinearLayout>

</LinearLayout>
但是,上面代码的结果是它将我返回到应用程序的第一页,然后仿真器关闭


我现在知道如何在c上实现这一点,但使用java我会:

listView.setOnItemClickListener(this);
让activity类实现侦听器,然后需要添加方法

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    Log.d(TAG, "onListItemClick: " + position);

    // you coce here
}
希望这有帮助