我想让我的班级显示数据库中的所有数据。在目前它我只显示一组数据,这将是标题,我试图改变他的代码,我认为将显示所有的数据
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"/>
答案 0 :(得分:1)
您更改了from
数组,但您还必须在列表行布局中to
数组(ids
的其他TextView
中添加一些ID {{1你会在哪里显示其他列。)
R.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.text1
和R.id.text2
是来自R.id.text3
的{{1}}的ID:
TextView