Android ListView with SQLite
I want to update the Listview items. These items are populated from the SQLite database. My code is below
public class Weeve extends Activity {
private String[] lv_arr;
protected ListView CView;
private DBAdapter mDbHelper;
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new DBAdapter(this);
mDbHelper.open();
Cursor c = mDbHelper.getAll();
if (c.getCount() > 0)
{if (c.moveToFirst())
{
ArrayList strings = new ArrayList();
do {
String mC = c.getString(0);
strings.add(mC);
} while (c.moveToNext());
lv_arr = (String[]) strings.toArray(new String[strings.size()]);
}
}
else Toast.makeText(this,
"No more Records",
Toast.LENGTH_SHORT).show();
c.close();
ListView CView = new ListView(this);
CView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, lv_arr));
setContentView(CView);}}
I would like to update this list view after adding, updating or deleting a SQLite table. These operations are called by content or in the options menu. I tried to create this code in a separate function and call it after each operation. But it cannot. I think the statement is setContentView (CView).
I also tried using SimpleCursorAdapter as a sample notepad from Android.com. I have an error in Thread. Help me.
+2
a source to share
2 answers