从数据库中显示标题和图像的最佳方式是什么?我只想一次显示一个数据行/记录,然后单击下一步按钮以显示下一个数据行/记录。我无法弄清楚哪些视图控件最好?我见过大量与 listview 相关的示例。
编号 | 标题 | 图片
1 春季 image1.blob 2 夏季 image2.blob 3 冬季 image3.blob
日志猫
06-07 04:33:06.213: E/Trace(950): error opening trace file: No such file or directory (2)
06-07 04:33:08.041: D/Insert:(950): Inserting ..
06-07 04:33:08.150: D/AndroidRuntime(950): Shutting down VM
06-07 04:33:08.150: W/dalvikvm(950): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-07 04:33:08.171: E/AndroidRuntime(950): FATAL EXCEPTION: main
06-07 04:33:08.171: E/AndroidRuntime(950): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sqlitedemoactivity/com.example.sqlitedemoactivity.SQLiteDemoActivity}: java.lang.NullPointerException
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.os.Looper.loop(Looper.java:137)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-07 04:33:08.171: E/AndroidRuntime(950): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 04:33:08.171: E/AndroidRuntime(950): at java.lang.reflect.Method.invoke(Method.java:511)
06-07 04:33:08.171: E/AndroidRuntime(950): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-07 04:33:08.171: E/AndroidRuntime(950): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-07 04:33:08.171: E/AndroidRuntime(950): at dalvik.system.NativeStart.main(Native Method)
06-07 04:33:08.171: E/AndroidRuntime(950): Caused by: java.lang.NullPointerException
06-07 04:33:08.171: E/AndroidRuntime(950): at com.example.sqlitedemoactivity.SQLiteDemoActivity.onCreate(SQLiteDemoActivity.java:37)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.Activity.performCreate(Activity.java:5104)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-07 04:33:08.171: E/AndroidRuntime(950): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-07 04:33:08.171: E/AndroidRuntime(950): ... 11 more
06-07 04:33:15.283: I/Process(950): Sending signal. PID: 950 SIG: 9
我的代码
private void setNewData(int position){
textview1 = (TextView)findViewById(R.id.textview1);
List<Contact> contacts = db.getContact(position) ;
for (Contact cn : contacts) {
String log = "ID:" + cn.getID() + " Name: " + cn.getName();
// Writing Contacts to log
Log.d("Name: ", log);
textview1.setText(cn.getName());
}
}
按钮点击代码
button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//increment the counter (which is keeps track of what position we are displaying.
counter = counter+1;
//call method to update the view with the next items position
setNewData(counter);
}
});