I have created one database with three table and place that database into the asset folder. Now I want to show the value from one column on a list view with checkboxes and then on user selection want to insert them into the another table. SO how can I do that.
Till now what I have done is to fetch the data and show on the list. But how can I place the checkboxes and then fetch the value I don't know. The code I used is below
1.Main Activity
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;
}
}
Please suggest me that how can I do this.. Any help must be appreciated