更新内容微调选择项目后,

编程入门 行业动态 更新时间:2024-10-28 10:26:14
本文介绍了更新内容微调选择项目后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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="schemas.android/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>

更多推荐

更新内容微调选择项目后,

本文发布于:2023-07-19 07:21:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154200.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!