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?

2
  • "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? Commented Apr 4, 2014 at 3: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. Commented Apr 4, 2014 at 3:55

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.