我创建了一个包含三个表的数据库,并将该数据库放入资产文件夹中。现在我想在带有复选框的列表视图中显示一列的值,然后在用户选择时将它们插入另一个表。那么我该怎么做。
到目前为止,我所做的是获取数据并显示在列表中。但是我怎样才能放置复选框,然后获取我不知道的值。我使用的代码如下
1.主要活动
package com.example;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
public class MainActivity extends ListActivity {
private Cursor employees;
private MyDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = new MyDatabase(this);
employees = db.getEmployees(); // you would not typically call this on the main thread
ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
employees,
new String[] {"FullName"},
new int[] {android.R.id.text1});
getListView().setAdapter(adapter);
}
@Override
protected void onDestroy() {
super.onDestroy();
employees.close();
db.close();
}
}
2.Mydatabase.java
package com.example;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "northwind";
private static final int DATABASE_VERSION = 2;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
//setForcedUpgradeVersion(2);
}
public Cursor getEmployees() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"0 _id", "FullName"};
String sqlTables = "Employees";
qb.setTables(sqlTables);
Cursor c = qb.query(db, sqlSelect, null, null,
null, null, null);
c.moveToFirst();
return c;
}
}
请建议我如何做到这一点..任何帮助都必须感谢