Note that there are some explanatory texts on larger screens.

plurals
  1. POCursor and Adapter
    text
    copied!<p>can someone see what I have wrong with my cursor: The data from the db is not returned (at least the screen is blank). I think that is my problem. In the DDMS shows it opens &amp; closes the db. I am not sure what 'Cursor databaseCursor = null;' needs to be. Thnx!!</p> <p>The Activity:</p> <pre><code> private void displayResultList() { Cursor databaseCursor = null; DomainAdapter databaseListAdapter = new DomainAdapter(this, R.layout.list_item, databaseCursor, new String[] { "label", "title", "description" }, new int[] { R.id.label, R.id.listTitle, R.id.caption }); databaseListAdapter.notifyDataSetChanged(); this.setListAdapter(databaseListAdapter); } private void openAndQueryDatabase() { if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { extStorageDirectory = Environment.getExternalStorageDirectory().toString(); File dbfile = new File(extStorageDirectory + "/Aero-Technologies/flyDroid/dB/flyDroid.db"); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null); Log.i("tag", "db opened"); try { db.rawQuery("SELECT * FROM AC_list", null); } finally { if (db != null) Log.i("tag", "db closed"); db.close(); } } else if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_UNMOUNTED)) { Log.i("tag", "SDCard is NOT writable/mounted"); Alerts.sdCardMissing(this); } } </code></pre> <p>My Adapter:</p> <pre><code>public class DomainAdapter extends SimpleCursorAdapter{ private Cursor dataCursor; private LayoutInflater mInflater; public DomainAdapter(Context context, int layout, Cursor dataCursor, String[] from, int[] to) { super(context, layout, dataCursor, from, to); this.dataCursor = dataCursor; mInflater = LayoutInflater.from(context); } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item, null); holder = new ViewHolder(); holder.text1 = (TextView) convertView.findViewById(R.id.label); holder.text2 = (TextView) convertView.findViewById(R.id.listTitle); holder.text3 = (TextView) convertView.findViewById(R.id.caption); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } dataCursor.moveToPosition(position); int label_index = dataCursor.getColumnIndex("label"); String label = dataCursor.getString(label_index); int title_index = dataCursor.getColumnIndex("title"); String title = dataCursor.getString(title_index); int description_index = dataCursor.getColumnIndex("discription"); String description = dataCursor.getString(description_index); holder.text1.setText(label); holder.text2.setText(title); holder.text3.setText(description); return convertView; } static class ViewHolder { TextView text1; TextView text2; TextView text3; } } </code></pre> <p>REVISED:</p> <p>Change the displayResultList method to the following (working):</p> <pre><code>private void displayResultList() { if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { extStorageDirectory = Environment.getExternalStorageDirectory() .toString(); File dbfile = new File(extStorageDirectory + "/Aero-Technologies/flyDroid/dB/flyDroid.db"); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null); Cursor databaseCursor = db.rawQuery("SELECT * FROM AC_list", null); DomainAdapter databaseListAdapter = new DomainAdapter(this, R.layout.list_item, databaseCursor, new String[] { "label", "title", "description" }, new int[] { R.id.label, R.id.listTitle, R.id.caption }); databaseListAdapter.notifyDataSetChanged(); this.setListAdapter(databaseListAdapter); } else if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_UNMOUNTED)) { Log.i("tag", "SDCard is NOT writable/mounted"); Alerts.sdCardMissing(this); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload