【问题标题】:Changing Tab Content Depending on Which Element of the Spinner is Selected根据选择的微调器的哪个元素更改选项卡内容
【发布时间】:2013-01-26 22:13:25
【问题描述】:

我正在尝试制作一个基于选项卡的应用程序,它是一个学校调度应用程序。

我在 activitiy_main.xml 中使用 tabhost 来使用所有数据(设置选项卡名称、元素等)。

我想要做的是有一个微调器(位于我的 tabhost 的 tab3 中)指示它下面显示的选项。

我有多个选项要显示。

这是位于我的 activity_main_xml 中的 tab3 的 XML 布局:

`

      <TextView
          android:id="@+id/labelAdd"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/add"
          android:textAppearance="?android:attr/textAppearanceLarge" />

      <Spinner
          android:id="@+id/addDropDown"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:entries="@array/type_array" />

      <Button
          android:id="@+id/StartTimeButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/addStartTime" />

      <TextView
          android:id="@+id/startTimeLabel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/addStartTime" />

      <TimePicker
          android:id="@+id/startTimePicker"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />

      <TextView
          android:id="@+id/endTimeLabel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/addEndTime" />

      <TimePicker
          android:id="@+id/endTimePicker"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />

      <TextView
          android:id="@+id/addRepeatQ"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/addRepeatQ" />

      <RadioGroup
          android:id="@+id/repeatRadioGroup"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" >

          <RadioButton
              android:id="@+id/addRepeatN"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:checked="true"
              android:text="@string/addRepeatN" />

          <RadioButton
              android:id="@+id/addRepeatY"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/addRepeatY" />
      </RadioGroup>

      <Button
          android:id="@+id/addNextButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/addNext" />

  </LinearLayout>`

我想让某些项目,特别是 startTimeLabel、StartTimeButton、endTimeLabel、endTimeButton 仅在选择我的微调器的某个元素时显示(在这种情况下,选择的项目将标题为“类”)。

对如何开始构建我的 .java 有任何帮助吗?我是 Android 编程新手,但在 java、html、php、sql 和 Visual Studio 方面有经验。

【问题讨论】:

    标签: android eclipse onclick spinner


    【解决方案1】:
    urSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) 
            {
                //write your code here what you want
                          change visibility of your Views(buttons,textviews) etc
    
            }
    
            public void onNothingSelected(AdapterView<?> arg0) {
    
    
            }
        });
    

    如果你有这个想法,请把它作为答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 2022-10-04
      • 2011-10-14
      • 2016-05-19
      • 2011-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多