2017-05-05 32 views
0

我有一個使用SimpleCursorAdapter填充的ListView。 listview顯示我的數據庫的一列的內容。該專欄只是我在數據庫中創建的課程(如英語,數學)。我也有每個課程的主題(如閱讀書寫..)。這也是同一張表的一列。在我的listView中它只顯示「英語」,但我想顯示「英語 - 閱讀」,所以我可以有所作爲。在SimpleView中使用SimpleCursorAdapter顯示多個列

我該怎麼做?

順便說一句,我的課的欄是'branche_cours',而我想顯示的另一欄是'指定'。

這裏是我的SimpleCursorAdapter

 lvCours =(ListView)findViewById(R.id.ListCours); 
    final Cursor cursor = dbhelper.getAllCours(); 
    String[] from = { "branche_cours" }; int[] to = { android.R.id.text1 }; 
    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, from, to, 0); 
    lvCours.setAdapter(adapter); 
    adapter.notifyDataSetChanged(); 
+0

我還沒找到解決方案呢.. – Dom

回答

0

爲您排項目佈局list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp"> 

    <TextView 
     android:id="@+id/text_branche_cours" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:text="English"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:text=" - " /> 

    <TextView 
     android:id="@+id/text_designation" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:text="Reading" /> 
</LinearLayout> 

enter image description here

2.要顯示branche_cours到TextView的R.id.text_branche_coursdesignation到TextView的R.id.text_designation,這樣做在你的Activity

lvCours = (ListView)findViewById(R.id.ListCours); 
final Cursor cursor = dbhelper.getAllCours(); 

String[] from = { "branche_cours", "designation" }; 
int[] to = { R.id.text_branche_cours, R.id.text_designation }; 

adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, from, to, 0); 
lvCours.setAdapter(adapter); 
adapter.notifyDataSetChanged(); 

這裏是一個不錯Tutorial

希望這會有所幫助〜

+0

很好的回答!謝謝 !它非常完美! – Dom

+0

高興地幫助:) – FAT

相關問題