重新当Android的微调设定值 [英] Android Spinner setting value when re

查看:193
本文介绍了重新当Android的微调设定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <Spinner
    android:id="@+id/spinner1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/editText2"
    android:layout_marginTop="22dp"
    android:entries="@array/categorylist"
    android:prompt="@string/category" />

我创建微调上述格式!

i have created spinner in the above format!

final Spinner spnr= (Spinner)findViewById(R.id.spinner1);
    String category=spnr.getSelectedItem().toString();

在上面的格式获得价值推入分贝微调值。

pushed the spinner values in db by getting value in above format.

现在,当从数据库中检索到的值。微调应根据具体的值设置...
我怎么能实现任何想法请??

now when values retrieved from db. the spinner should set according to specific value... how can i implement any ideas pls??

推荐答案

只有当你存储设置为微调的条目的项目的数组,可以是可能的。您可以在微调所选项目的位置。所以,你必须发现你从数据库中查询该项目的索引。加载所属分类的字符串数组和遍历数组,每个项目从数据库中获取的项目进行比较。然后设置,找到的项目指标为微调选定的项目。

That can be possible only when you store the array of the items that are set as entries of Spinner. You can set the position of the selected item in spinner. So you have to find out index of the item that you query from the database. Load the StringArray of categorylist and iterate the array and compare each item with the item fetched from the database. Then set the index of the found item as selected item in spinner.

    String[] list = getResources().getStringArray(R.array.categorylist);
    int index = 0;
    for(String item : list) {
        if(item.equals("your_item")){
            break;
        }
        index++;
    }
    spinner.setSelection(index);

这篇关于重新当Android的微调设定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆