Android Spinner - How to remove radio buttons?

In Android 1.6, when you click on the drop-down menu (spinner), switches appear next to the spinner settings. How to remove these switches so that the text of the text remains?

+5
source share
7 answers

Just to remove the switches you don’t need your own adapter class.

Create dropdown_item.xml in layout

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee" />

then execute the following code in the code.

arrayAdapter.setDropDownViewResource(R.layout.dropdown_item);

The default spinner dropdown is a CheckedTextView, which has a switch. Here you replace it with a TextView.

+23
source

You can use android layout

android.R.layout.simple_spinner_item 

instead

android.R.layout.simple_spinner_dropdown_item

@kimkunjj, .

+5

, .
:


package com.ramps;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

public class MySpinner extends Activity {
    //data that will be used as a spinner options
    private static String data[] = {"one", "two", "three"};

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //main.xml file contains spinner
        setContentView(R.layout.main);
        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        //create your own adapter
        MySpinnerAdapter adapter = new MySpinnerAdapter(this,R.layout.custom_spinner_row,R.id.text, data );
        //set your custom adapter 
        spinner.setAdapter( adapter );
    }


    private class MySpinnerAdapter extends ArrayAdapter{

        public MySpinnerAdapter(Context context, int resource,
                int textViewResourceId, String[] objects) {
            super(context, resource, textViewResourceId, objects);          
        }   

    }
}


spinner - LinearLayout TextView, "" (android: id = "@+ id/text" )

. , TextView, , , getView() MySpinnerAdapter.

+4

"android.R.layout.simple_spinner_item" ,

:

modeSpinner=new Spinner(layout.getContext());
ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(layout.getContext(),     
    android.R.layout.simple_spinner_item, Arrays.asList(modes));
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
+1

Android 18 , simple_spinner_dropdown_item support_simple_spinner_dropdown_item. .

+1

simple_dropdown_item_1line

+1

" " ( anythinbg else, , ..) (, ):

public class SimpleSpinnerArrayAdapter extends ArrayAdapter<String> {

    public SimpleSpinnerArrayAdapter(Context context, String[] data) {
        super(context, android.R.layout.simple_spinner_item, data);
        this.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    }

    public SimpleSpinnerArrayAdapter(Context context, List<String> data) {
        super(context, android.R.layout.simple_spinner_item, data);
        this.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    }

    /**
     * Returns default dropdown view with removed checkbox
     */
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View view = super.getDropDownView(position, convertView, parent);
        if (view != null && view instanceof CheckedTextView) {
            ((CheckedTextView) view).setCheckMarkDrawable(null);
        }
        return view;
    }
}

getDropDownView(), . , , , , .

0
source

All Articles