在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)
答案 0 :(得分:0)
使用此代码可以隐藏您的微调器。
spinnermo.setVisibility(View.GONE);
如果你想隐藏单选按钮使用相同的代码
radioButton.setVisibility(View.GONE);
答案 1 :(得分:0)
是创建两个布局,因为一旦实现了ArrayAdapter,它将有两个方法可以覆盖getView和getDropDownView
<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;
<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;
然后在您的自定义适配器类
中重写方法以分别访问上述值
@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;