setSelection on Spinner based on rowId

前端 未结 7 701
离开以前
离开以前 2020-12-14 22:19

I have a Spinner View that\'s populated through a SimpleCursorAdapter.

Based on the selection I need to save the rowid in the entry database (posit

7条回答
  •  失恋的感觉
    2020-12-14 22:33

    I think that instead of a for loop is better a while, because when you find your item, can break the loop.

    int spinnerCount = spinner.getCount();
    int i = 0;
    while(i++ < spinnerCount) {
        Cursor value = (Cursor) spinner.getItemAtPosition(i);
        long id = value.getLong(value.getColumnIndex("_id"));
        if (id == rowid) {
            spinner.setSelection(i);
            break;
        }
    }
    

提交回复
热议问题