2012-04-03 41 views
1

我想讓我的類顯示數據庫中的所有數據。在當前時間它,我只顯示了一組數據,這將是冠軍,我試圖改變他的代碼是什麼我認爲會顯示所有獲取數據庫行中的所有數據以顯示Android SQLite

public class WorkoutProgress extends ListActivity { 
private DataBaseHelper datasource; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.progress); 

    datasource = new DataBaseHelper(this); 
    datasource.open(); 
    fillData(); 
    datasource.close(); 
} 
private void fillData() { 
     // Get all of the notes from the database and create the item list 
     Cursor c = datasource.getAllTitles(); 
     startManagingCursor(c); 

     String[] from = new String[] { DataBaseHelper.KEY_TITLE,DataBaseHelper.KEY_ISBN, DataBaseHelper.KEY_PUBLISHER }; 
     int[] to = new int[] { R.id.text1 }; 

     // Now create an array adapter and set it to display using our row 
     SimpleCursorAdapter notes = 
      new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); 
     setListAdapter(notes); 
    } 

    } 

我想的代碼我需要改變的是數據這條線

 String[] from = new String[] { DataBaseHelper.KEY_TITLE}; 

向該線

 String[] from = new String[] { DataBaseHelper.KEY_TITLE,DataBaseHelper.KEY_ISBN, DataBaseHelper.KEY_PUBLISHER }; 

這是notes_row.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView android:id="@+id/text1" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/> 
<TextView android:id="@+id/text2" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/> 
<TextView android:id="@+id/text3" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/> 

回答

1

你改變from數組,但你還必須將to陣列中添加一些IDS(在列表中排佈置其他TextView S的idsR.layout.notes_row),您會顯示其他列。)

String[] from = new String[] { DataBaseHelper.KEY_TITLE,DataBaseHelper.KEY_ISBN, DataBaseHelper.KEY_PUBLISHER }; 
int[] to = { R.id.text1, R.id.text2, R.id.text3 }; 

其中R.id.text1R.id.text2R.id.text3TextView的ID從R.layout.notes_row

<?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="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/text3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 
+0

,所以我也將增加更多的Textv在note_row中查看,然後將新的textViews放入'to'數組中? – 2012-04-03 14:22:02

+1

@DarrenMurtagh是的,否則應該在哪裏顯示數據? – Luksprog 2012-04-03 14:23:40

+0

當我將xml更改爲xml上面添加的內容時說有錯誤 – 2012-04-03 14:28:12

相關問題