Question

Ive been struggling for a while with my rather simple app. This is my onCreate in my listactivity class:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    DB db = new DB(this);
    db.open();
    cur = db.getData(); //cursor with all data from an SQLite db

    String[] from = new String[] { DB.KEY_FIRSTNAME,
            DB.KEY_LASTNAME, DB.KEY_BDATE};
    int[] to = new int[] { NOT SURE WHAT TO PUT HERE };
    startManagingCursor(cur);
    setListAdapter(new SimpleCursorAdapter(this, 
    android.R.layout.simple_list_item_1, cur, from, to));

    db.close();

    }

The getData() method returns a cursor from an sqlite database. the int[] used by the adapter defined over is where I think the problem lies, but I have no idea how to solve it. The list I get out is either blank. Only lines resembling the number of entries in the database or only 1 of the columns. I have tried int[] {android.R.id.text1, android.R.id.text1, android.R.id.text1, android.R.id.text1} and fewer entries, and text2 and Ive now tried to just make a textview and call that, but then it goes completely blank again.

I hope you can help me wrap my head around this. Thanks!

Was it helpful?

Solution

Your to variable stores the R.id's of where you want to map your data to. For example, if the layout (android.R.layout.simple_list_item_1) has three TextViews in it, named fName, lName and bDate you would place those in the int array and it will map the data in the from fields to the on screen layout components in the to fields.

int[] to = new int[] {R.id.fName, R.id.lName, R.id.bDate};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top