更新内容微调选择项目后, [英] Update content after selecting item in spinner

查看:104
本文介绍了更新内容微调选择项目后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其再次我。我想最后一个小时,如何更改微调的内容。
好吧,让我们从头开始。

its me again. I tried the last hours, how to change content of a spinner. ok, lets start from the beginning.

我有三个纱厂。他们都有初始值。第一个微调是主要的微调,其他两个纱厂依赖于第一个选择的山谷。所以我想在微调一条所述的选择后更新的最后两个微调。 *编辑:所有纺纱在同一个活动

I have three spinners. They all have initial values. The first spinner is the main spinner and the other two spinners depend on the vale chosen in the first one. So i want to update the last two spinners after making a selection in spinner one. *edit: All spinners are on the same activity.

我怎样才能做到这一点?我的问题是,我只能在onitemselectadapter的微调变化,但多数民众赞成一个全新的类。我无法到达的地方我的其他微调器的活动。

How can i achieve this? My problem is that i can only make changes in the spinners onitemselectadapter but thats a whole new class. I cannot reach the activity where my other spinners are.

THX

推荐答案

是你的纺纱厂在不同的活动?

Are your spinners in different activities?

如果是这样,那么你可以通过通过第一微调的价值选择意向(见putExtra部分),并从下一个活动检索值,这样就可以设置相应的下一个微调。

If they are, so you can just pass the selected value of the first spinner via Intent (See the putExtra section) and retrieve the value from the next activity so that you can set accordingly the next spinners.

编辑:

下面的是,在第二和第三旋转器改变所选择的项目的例子。用你的逻辑更新监听器(onItemSelected法)

Here is an example that changes the selected item in the 2nd and 3rd spinner. Update the listener (onItemSelected method) with your logic

活动:

private Spinner s;
private Spinner s2;
private Spinner s3;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    String[] myList = new String[] { "Hello", "World", "Foo", "Bar" };
    String[] myList2 = new String[] { "Hello2", "World2", "Foo2", "Bar2" };
    String[] myList3 = new String[] { "Hello3", "World3", "Foo3", "Bar3" };

    s = (Spinner) findViewById(R.id.spinner1);
    s2 = (Spinner) findViewById(R.id.spinner2);
    s3 = (Spinner) findViewById(R.id.spinner3);

    s.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, myList));
    s2.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, myList2));
    s3.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, myList3));


    s.setOnItemSelectedListener(new OnItemSelectedListener(){

        @Override
        public void onItemSelected(AdapterView<?> parent, View v,
                int pos, long id) {
            s2.setSelection(pos);
            s3.setSelection(pos);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {


        }});
}

main.xml中:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_height="wrap_content"
        android:orientation="vertical">
<Spinner android:id="@+id/spinner1" android:layout_height="wrap_content" android:layout_width="fill_parent" />
<Spinner android:id="@+id/spinner2" android:layout_height="wrap_content" android:layout_width="fill_parent" />
<Spinner android:id="@+id/spinner3" android:layout_height="wrap_content" android:layout_width="fill_parent" />
</LinearLayout>

这篇关于更新内容微调选择项目后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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