隐藏微调器选定值的单选按钮

时间:2012-03-21 09:11:56

标签: android

在android中使用spinner,布局为(android.R.layout.simple_spinner_dropdown_item) 因为我需要那里的单选按钮,但在我选择一个值后,单选按钮仍然显示在微调器上。他们有什么方法可以隐藏它吗?

这是我的微调器:

        <Spinner
              android:id="@+id/Spinner01"
              android:layout_width="fill_parent"
              android:layout_height="40dip"
              android:layout_gravity="left"
              android:background="@drawable/spin" >

        </Spinner>

这是活动线:

ArrayAdapter first_adapter = new ArrayAdapter(this,  android.R.layout.simple_spinner_dropdown_item, start_list);
         spinnermo.setAdapter(first_adapter);

这是选择后的微调器: 噢,我不能把这张图片显示出来,但它的表情符号是这样的:

seleced text (0)

2 个答案:

答案 0 :(得分:0)

使用此代码可以隐藏您的微调器。

spinnermo.setVisibility(View.GONE);

如果你想隐藏单选按钮使用相同的代码

radioButton.setVisibility(View.GONE);

答案 1 :(得分:0)

是创建两个布局,因为一旦实现了ArrayAdapter,它将有两个方法可以覆盖getView和getDropDownView

  1. 对于getDropDownView,您必须使用TextView创建布局并在其中设置相应的值
  2. &#13;
    &#13;
    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/your_own_unique_id_for_checkedtextview"
        style="?android:attr/spinnerDropDownItemStyle"
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/dropdownListPreferredItemHeight"
        android:ellipsize="marquee"/>
    &#13;
    &#13;
    &#13;

    1. 对于getView,您必须使用CheckedTextView创建布局并调用相应的方法
    2. &#13;
      &#13;
       <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
          android:id="@+id/your_own_unique_id_for_textview"
          style="?android:attr/spinnerItemStyle"
          android:singleLine="true"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ellipsize="marquee"
          android:textAlignment="inherit"/>
      &#13;
      &#13;
      &#13;

      然后在您的自定义适配器类

      重写方法以分别访问上述值

      &#13;
      &#13;
      @Override
          public View getDropDownView(int position, View convertView,ViewGroup parent) {
              return getCustomCheckedTextView(position, convertView, parent);
          }
      
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              return getCustomTextView(position, convertView, parent);
          }
      
          // This funtion called for each row ( Called data.size() times )
          public View getCustomCheckedTextView(int position, View convertView, ViewGroup parent) {
      
              /********** Inflate spinner_rows.xml file for each row ( Defined below ) ************/
              View row = inflater.inflate(R.layout.your_own_layoutxml_file_name, parent, false);
      
              /***** Get each Model object from Arraylist ********/
              
              CheckedTextView label        = (CheckedTextView)row.findViewById(R.id.your_own_id_for_checkedtextview);
              // Set values for spinner each row
              label.setText("value");
      
      
              return row;
          }
      
          // This funtion called for each row ( Called data.size() times )
          public View getCustomTextView(int position, View convertView, ViewGroup parent) {
      
              /********** Inflate spinner_rows.xml file for each row ( Defined below ) ************/
              View row = inflater.inflate(R.layout.your_own_layout_xml_file_name_for_textview, parent, false);
      
              TextView label        = (TextView)row.findViewById(R.id.your_text_view_id_name);
              // Set values for spinner each row
              label.setText("value");
      
              return row;
          }
      &#13;
      &#13;
      &#13;