填充微调从SQLite数据库的Andr​​oid数据库、SQLite、oid、Andr

2023-09-12 21:50:44 作者:咸鱼翻身还特么是咸鱼

我试图做一个动态下拉将由一个SQLite表填写。我有一个游标对象,我可以拉我需要的数据。我已经能够做到把值装载入的下拉低于code:

I'm attempting to make a dynamic drop down that will be filled by a SQLite table. I have a Cursor object which I can pull the data I need from. I've been able to accomplish loading the values into the drop down with the code below:

Spinner s = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s.setAdapter(adapter);

    try{
        Cursor cursor = getAccounts();
        int accountnameIndex = cursor.getColumnIndexOrThrow(ACCOUNT_NAME);
        if(cursor.moveToFirst()){
            do{
                adapter.add(cursor.getString(accountnameIndex));
            } while(cursor.moveToNext());
        }
    } finally {
        MintLink.close();
    }

我的问题是,我需要从下拉菜单中选择也包含所选项目的ROWID。我需要能够选择一个项目,并访问该项目的值在后端。例如,考虑一个下拉在HTML中。每个下拉选项都有一个把它自己的隐藏价值。我需要这个值被隐藏了我,让我知道他们选择哪个ID。

My problem is that I need the a selection from the drop down to also contain the RowID of the item selected. I need to be able to select one item and have access to the value of that item in the back end. For example, think of a drop down in HTML. Each drop down selection has it's own hidden value that is pulled. I need this value to be hidden for me to allow me to know which ID they choose.

推荐答案

尝试使用 SimpleCursorAdapter ,而不是手工复制所有数据到一个 ArrayAdapter

Try using a SimpleCursorAdapter instead of copying all the data by hand into an ArrayAdapter.