In the following code I want to use the external database to adapter a Listview in onCreate no problem, the database copy and open. In onResume mCursor receives all existing rows, still no problem and TextView contentlop is displayed. But when SimpleCursorAdapter added, the code does not run.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tow);
contentLog = (TextView) findViewById(R.id.txtzz);
mylist=(ListView)findViewById(R.id.mylist);
myDbHelper = new DataBaseHelper(this.getApplicationContext());
myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.createDataBase();
contentLog.append("Database Created\n");
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
contentLog.append("Database Opened\n");
} catch (SQLException sqle) {
sqle.printStackTrace();
}
db = myDbHelper.getReadableDatabase();
contentLog.append("Get the readable database\n");
}
@Override
protected void onResume() {
super.onResume();
mCursor= db.rawQuery("SELECT title,entity_id FROM khotbe ;",null);
mCursor.moveToFirst();
String[] headers = new String[] {"title","entity_id"};
contentLog.append("Select:\t" + mCursor.getColumnCount() + " cols, "+ mCursor.getCount() + " rows\n");
mAdapter = new android.support.v4.widget.SimpleCursorAdapter(tow.this,R.layout.myitme,mCursor, headers, new int[]{R.id.txt25,R.id.txt26},0);
mylist.setAdapter(mAdapter);
}
Here is my code to work properly:
contentLog.append("Select:\t" + mCursor.getColumnCount() + " cols, "+ mCursor.getCount() + " rows\n");
But SimpleCursorAdapter does not work
Aucun commentaire:
Enregistrer un commentaire