如何将所选微调器项的可见性设置为false

时间:2013-10-11 14:12:06

标签: android android-spinner

我为我的微调器设置了背景图像,但是当我从微调器的下拉列表中选择一个项目时,我的微调器背景图像被所选项目替换,我希望我的背景图像保留在那里,我不希望显示所选项目而不是旋转器的背景图像。我该怎么做?

我的自定义适配器的代码:

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;
    }
}

我的自定义微调器xml的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
     >

    <TextView
        android:id="@+id/text_main_seen"
        android:layout_width="fill_parent"
        android:layout_height="30sp"
        android:background="#008000"
        android:gravity="center"

        android:textColor="#ffffff"
        android:textSize="30px" />

</RelativeLayout>

我实际的spinner.xml的代码

<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

和我调用微调器的mainActivity的代码是

Spinner mySpinner = (Spinner) findViewById(R.id.planets_spinner);
    mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner,
            spinnerValues));

1 个答案:

答案 0 :(得分:0)

我根本不会使用微调器。只需使用一个看起来像Spinner的Button或任何你想要它的样子。您可以使用此属性使常规Button看起来像Spinner:

android:background="@android:drawable/btn_dropdown"

或者,使自己的背景看起来像一个Spinner并使用它。

然后,让Button的onClick事件打开“单项选择”对话框。

相关问题