2012-04-03 43 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

相关问题