0

嗨,我正在编写我的第一个可用的 android 应用程序。我有以下查询,有没有办法根据微调器中选择的值填充 flyed 的值。

eg When country A is selected , 3 values are shown .

在此处输入图像描述

But when country B is selected, only 2 values are shown.

在此处输入图像描述

有没有办法在 Android 屏幕上实现这一点?有人可以提供一些例子或指出我正确的方向。

4

1 回答 1

0

我认为这个例子可以帮助你不确定。我正在创建一个线性布局,我将在其上添加所有选项。我正在管理哈希图中的选项。您可以根据您的要求进行更改。

这是我的主要活动:

 public class MainActivity extends Activity {

        HashMap <String, CheckBox> options = new HashMap<String, CheckBox>();

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            int number_of_options = 2;
            for (int i = 0; i < number_of_options; i ++) {
                create_view("option "  + i);
            }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }



    private void create_view(String option)
            {
                LinearLayout layout = new LinearLayout(getApplicationContext());
                layout.setOrientation(LinearLayout.VERTICAL);
                TextView text_option = new TextView(getApplicationContext());
                text_option.setText(option);
                CheckBox check_box = new CheckBox(getApplicationContext());
                layout.addView(text_option);
                layout.addView(check_box);
                LinearLayout inner_layout = (LinearLayout) findViewById(R.id.linear_layout);
                inner_layout.addView(layout);
                options.put(option, check_box);
            }
    }

create_view 将为您创建选项。

这是我的 XML 布局:

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="28dp" />

<LinearLayout
    android:id="@+id/linear_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/spinner1"
    android:layout_below="@+id/spinner1"
    android:orientation="horizontal" >

</LinearLayout>

我只是在创建一个线性布局并在其上添加选项。如果您有任何疑问,那么您可以要求我会尽力提供帮助。我不管理选项之间的保证金。

于 2013-10-08T06:51:59.050 回答