Android片段中的多个旋转器

时间:2015-12-15 20:11:23

标签: android android-fragments android-spinner

好吧,我对此完全陌生 -

我基本上想要做的是,在一个Android片段中我有多个Radio Buttons和Spinners。只有当启用了特定的单选按钮时,其相应的Spinner才会被设置为启用(真),具体取决于已选择的特定微调器的项目,我将在另一个片段中显示一个字符串。

当我选择微调器的第二个(索引:1)元素时,一切正常。但是当我选择任何微调器的第一个元素(索引:0)时,它会转到最后一个微调器和字符串根据最后一个微调器的第一个索引显示下一个片段!

为什么会出现问题?这是我的代码段:

    head_spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            switch (position) {
                case 0:
                    description = "First element of Spinner 1";
                    break;

                case 1:
                    description = "Second element of Spinner 1";
                    break;

                default:
                    description = "First element of spinner 1";
                    break;


            }


        }

        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    head_spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position2, long id) {
            switch (position2) {
                case 0:
                    description = "First element of Spinner 2";
                    break;

                case 1:
                    description = "Second element of Spinner 2";
                    break;


            }

        }


        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    head_spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position3, long id) {
            switch (position3) {
                case 0:
                    description = "First element of Spinner 3";
                    break;

                case 1:
                    description = "Second element of Spinner 3";
                    break;

                default:
                    description = "First element of Spinner 3";
                    break;


            }
        }


        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    manager = getFragmentManager();


    head_btn1.setOnClickListener(new View.OnClickListener() {
                                     @Override
                                     public void onClick(View v) {


                                         Fragment f1 = new Description();
                                         FragmentManager fm = getFragmentManager();
                                         android.app.FragmentTransaction ft = fm.beginTransaction();
                                         Bundle args = new Bundle();
                                         args.putString("DESCRIPTION", description);
                                         f1.setArguments(args);
                                         ft.replace(R.id.group1, f1, "A");
                                         ft.commit();


                                     }

                                 }
    );


}

}

当输出应该实际显示&#34; Spinner 1的第一个元素&#34; /&#34;旋转器2的第一个元素&#34; - 它给出了#3; Spinner 3的第一个元素&#34;。

然而,它适用于其他情况,任何想法为什么它不能正常工作?

0 个答案:

没有答案