Android 如何将微调器选定项的可见性设置为false
我为微调器设置了一个背景图像,但当我从微调器的下拉列表中选择一个项目时,我的微调器背景图像将替换为所选项目,我希望我的背景图像保留在那里,我不希望显示所选项目而不是微调器的背景图像。我该怎么做 自定义适配器的代码:Android 如何将微调器选定项的可见性设置为false,android,android-spinner,Android,Android Spinner,我为微调器设置了一个背景图像,但当我从微调器的下拉列表中选择一个项目时,我的微调器背景图像将替换为所选项目,我希望我的背景图像保留在那里,我不希望显示所选项目而不是微调器的背景图像。我该怎么做 自定义适配器的代码: public class MyAdapter extends ArrayAdapter<String> { public MyAdapter(Context ctx, int txtViewResourceId, String[] objects) {
public class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context ctx, int txtViewResourceId, String[] objects) {
super(ctx, txtViewResourceId, objects);
}
@Override
public View getDropDownView(int position, View cnvtView, ViewGroup prnt) {
return getCustomView(position, cnvtView, prnt);
}
@Override
public View getView(int pos, View cnvtView, ViewGroup prnt) {
return getCustomView(pos, cnvtView, prnt);
}
public View getCustomView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View mySpinner = inflater.inflate(R.layout.custom_spinner, parent,
false);
TextView main_text = (TextView) mySpinner
.findViewById(R.id.text_main_seen);
main_text.setText(spinnerValues[position]);
return mySpinner;
}
}
我根本不会用旋转器来做这个。只需使用一个看起来像旋转器的按钮或任何你想让它看起来像的东西。可以使用以下属性使常规按钮看起来像微调器:
android:background="@android:drawable/btn_dropdown"
或者,制作自己的背景,看起来像一个旋转器,并使用它
然后,让按钮的onClick事件打开一个“单项选择”对话框。你能发布代码吗?这个问题似乎重复了,请查看这些帖子和
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:id="@+id/planets_spinner"
android:layout_width="100dp"
android:layout_height="50sp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#008000"
android:layout_weight="0.08"
android:drawSelectorOnTop="true" />
</RelativeLayout
Spinner mySpinner = (Spinner) findViewById(R.id.planets_spinner);
mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner,
spinnerValues));
android:background="@android:drawable/btn_dropdown"