有没有办法让微调器选项打开另一个微调器?

发布于 2024-12-06 22:59:13 字数 456 浏览 1 评论 0原文

我希望当有人单击微调器中的选项时,它会打开另一个包含更多选项的微调器。另外,是否有一种方法可以让“其他”选项打开一个 EditText,如果微调器中没有他们的选择,则可以在其中输入他们的选择?

示例:

Spinner 1 有以下选项:

iOS

Android

如果他们选择 iOS,则会立即出现另一个微调器,其中选项是所有 iPhone 版本。 (即,标题为“您拥有哪款 iPhone?”)

如果他们选择 Android,它会执行相同的操作,但使用的是 Android 设备。

如果他们的手机不在第二个旋转器上,他们会输入手机型号。

如果我的代码中已经有第一个旋转器,我该怎么做?

PS,如果需要,我可以发布第一个旋转器的代码,尽管它非常标准。

I want it where when someone clicks an option in a Spinner, it opens another spinner with more options. Also, is there a way for an "Other" option to open an EditText where someone can input their selection if theirs isn't available in the Spinner?

Example:

Spinner 1 has these options:

iOS

Android

And if they select iOS, another spinner comes up immediately where the options are all the iPhone versions. (i.e., titled "Which iPhone do you have?")

And if they select Android, it does the same thing, but with Android devices.

AND if their phone isn't on the second spinner, they type the model of their phone in.

How could I do this if I have the first spinner already in my code?

P.S., if needed, I can post the code for the first spinner, though it's pretty standard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微暖i 2024-12-13 22:59:13

基本上根据他们选择的选项以编程方式构建第二个旋转器。我会在每个第二个旋转器中添加“其他”。如果他们选择“其他”,那么您可以显示文本框。

Basically build your second spinner programmatically depending on which option they choose. I'd add "other" to each second spinner. If they choose "other" then you can display the text box.

長街聽風 2024-12-13 22:59:13

我希望这对你有用。

试试这个代码...

public class MainActivity extends Activity {

Spinner sp1,sp2;
ArrayAdapter<String> adp1,adp2;
List<String> l1,l2;
int pos;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    l1=new ArrayList<String>();

    l1.add("A");
    l1.add("B");

    sp1= (Spinner) findViewById(R.id.spinner1);
    sp2= (Spinner) findViewById(R.id.spinner2);

    adp1=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,l1);
    adp1.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    sp1.setAdapter(adp1);

    sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub
            pos=arg2;
            add();

        }

        private void add() {
            // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(), ""+pos, Toast.LENGTH_SHORT).show();

            switch(pos)
            {
            case 0:
                l2= new ArrayList<String>();                    
                l2.add("A 1");
                l2.add("A 2");

                adp2=new ArrayAdapter<String>(MainActivity.this,
                        android.R.layout.simple_dropdown_item_1line,l2);
                adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                sp2.setAdapter(adp2);

                select();

                break;
            case 1:
                l2= new ArrayList<String>();                    
                l2.add("B 1");
                l2.add("B 2");

                adp2=new ArrayAdapter<String>(MainActivity.this,
                        android.R.layout.simple_dropdown_item_1line,l2);
                adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                sp2.setAdapter(adp2);

                select();

                break;
            }

        }

        private void select() {
            // TODO Auto-generated method stub

            sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getBaseContext(), "Test "+arg2, Toast.LENGTH_SHORT).show();

                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub

                }
            });

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });
    }

}

I hope this will be useful to you.

Try this Code...

public class MainActivity extends Activity {

Spinner sp1,sp2;
ArrayAdapter<String> adp1,adp2;
List<String> l1,l2;
int pos;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    l1=new ArrayList<String>();

    l1.add("A");
    l1.add("B");

    sp1= (Spinner) findViewById(R.id.spinner1);
    sp2= (Spinner) findViewById(R.id.spinner2);

    adp1=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,l1);
    adp1.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    sp1.setAdapter(adp1);

    sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub
            pos=arg2;
            add();

        }

        private void add() {
            // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(), ""+pos, Toast.LENGTH_SHORT).show();

            switch(pos)
            {
            case 0:
                l2= new ArrayList<String>();                    
                l2.add("A 1");
                l2.add("A 2");

                adp2=new ArrayAdapter<String>(MainActivity.this,
                        android.R.layout.simple_dropdown_item_1line,l2);
                adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                sp2.setAdapter(adp2);

                select();

                break;
            case 1:
                l2= new ArrayList<String>();                    
                l2.add("B 1");
                l2.add("B 2");

                adp2=new ArrayAdapter<String>(MainActivity.this,
                        android.R.layout.simple_dropdown_item_1line,l2);
                adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                sp2.setAdapter(adp2);

                select();

                break;
            }

        }

        private void select() {
            // TODO Auto-generated method stub

            sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getBaseContext(), "Test "+arg2, Toast.LENGTH_SHORT).show();

                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub

                }
            });

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文