我先从一个LQ数据库生成一份名单,但坐在如何增加每份名单的聆听器上,以便当某个项目被点击时,我可以再展示一页关于该项目的更多信息。 数据库只是一个样本。 希望得到任何帮助。
public class Database extends ListActivity {
private final String SAMPLE_DB_NAME = "myFriendsDb";
//private final String SAMPLE_TABLE_NAME = "friends";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<String> results = new ArrayList<String>();
SQLiteDatabase db = null;
try {
db = this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS people" +
" (LastName VARCHAR, FirstName VARCHAR," +
" Country VARCHAR, Age INT(3));");
db.execSQL("INSERT INTO people" +
" Values ( Jones , Bob , UK ,30);");
db.execSQL("INSERT INTO people" +
" Values ( Smith , John , UK ,40);");
db.execSQL("INSERT INTO people" +
" Values ( Thompson , James , UK ,50);");
Cursor c = db.rawQuery("SELECT FirstName, LastName FROM people", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String firstName = c.getString(c.getColumnIndex("FirstName"));
String lastName = c.getString(c.getColumnIndex("LastName"));
results.add("" + firstName + " " + lastName);
iiiwhile (c.moveToNext());
iii
iii
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
iii catch (SQLiteException se ) {
Log.e(getClass().getSimpleName(), "Could not create or Open the database");
iii finally {
if (db != null)
db.execSQL("DELETE FROM people");
db.close();
iii
iii
iii