开发者

How to get back spinner data

开发者 https://www.devze.com 2023-04-11 05:50 出处:网络
I filled a spinner with a query. How can I retrieve the information that I selected? I\'m having trouble with getSelectedItem(position)..

I filled a spinner with a query.

How can I retrieve the information that I selected? I'm having trouble with getSelectedItem(position)..

I have a cursor where I save the query, I fill the spinner that's no problem. But I don't know how to assign to a string the variable I selected in the spinner.

For example

spinnerNAME.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent,
                android.view.View v, int position, long id) {
                    selEntidad = ??;
            }

            public void onNothingSelected(AdapterView<?> parent) {
                  selEntidad ="noData";
            }
    });

How can I put in selEntidad the val开发者_C百科ue of what I selected in the spinner, that I filled with a query?


If you pass strings to the spinner you should be able to get the corresponding string with
(String) parent.getItemAtPosition(position).

getItemAtPosition will always return the object the adapter uses to construct the views. So in case of a SimpleCursorAdapter you get the cursor at this position. You can cast the returned object to Cursor and then query your data. E.g. getString(0) if you have a string in the first column of the queried cursor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号