1

I currently have an application that contains a listView that is populated from the sqlite database. The ListView contains two texts views for each item, one for the name and one for the status. A status is displayed either by a 0 or a 1 like true or false. I would like to make each item that contains the number 0 or 1 as the status to display open or closed.

methods for the listview:

// Return all data in the database.
    public Cursor getAllRows() {
        String where = null;
        Cursor c = ourDatabase.query(true, DATABASE_TABLE, ALL_KEYS, where,
                null, null, null, null, null);
        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }

    // also added
    // Get a specific row (by rowId)
    public Cursor getRow(long rowId) {
        String where = KEY_ROWID + "=" + rowId;
        Cursor c = ourDatabase.query(true, DATABASE_TABLE, ALL_KEYS, where,
                null, null, null, null, null);
        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }

Here is my listView code:

private void loadListView() {
    // TODO Auto-generated method stub
    Locker getList = new Locker(this);
    getList.open();
    Cursor cursor = getList.getAllRows();
    startManagingCursor(cursor);
    // setup mapping
    String[] fromFieldNames = new String[] { getList.KEY_LOCKERNUMBER,
            getList.KEY_STATUS };

    int[] toViewIDs = new int[] { R.id.tvLockerNumber, R.id.tvSatus };

    // create adapter
    SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,
            R.layout.itemlayout, cursor, fromFieldNames, toViewIDs);

    // set the adapter
    ListView myList = (ListView) findViewById(R.id.lvInfo);
    myList.setAdapter(myCursorAdapter);
}

How can I go about doing this?

RedShirt
  • 855
  • 2
  • 20
  • 33
  • "I would like to make each item that contains the number 0 or 1 as the status to display open or closed." What do you mean by open or closed? Are you talking about different layouts? – FMontano Apr 04 '14 at 03:26
  • Within the list view currently its get the status variable from my database which can either be a 0 or a 1. I would like my list view to interpret those integers and display on the textview to say Open or Close. – RedShirt Apr 04 '14 at 03:55

1 Answers1

1

You will have to implement the method setViewValue of myCursorAdapter so you can set the textview to Open or Close when 1 or 0.

Take a look to this answer for an exmample. Also, look at the developer's guide for more details.

Community
  • 1
  • 1
FMontano
  • 907
  • 8
  • 17