2012-04-28 3 views
-2

SQL Server에서 쿼리 된 이름의 DataTable이 있습니다. 그 이름을 사용하여 .axml 파일에서 만든 ListView를 채우고 싶습니다. 이것을 처리하는 가장 좋은 방법은 무엇입니까? 이것은 내가 지금까지 무엇을 가지고 :Monodroid : 어떻게 SQL에서 가져 오는 DataTable의 데이터로 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> 

그러나, 위의 코드의 결과는 응용 프로그램의 첫 페이지에 저를 반환하고, 다음 에뮬레이터가 종료됩니다.

The android device logging show those errors

나는 C#을에이를 구현하는 방법을 이제 확신하지만 난 것 자바 사용하여 최대한 빨리

답변

0

도와주세요 : 활동 클래스가 리스너를 구현하는 분들께

listView.setOnItemClickListener(this); 

및 그 방법을 추가해야합니다.

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

    // you coce here 
} 

희망이 있습니다.

관련 문제