In Android 1.6, upon tapping a spinner (drop-down menu), radio buttons appear next to the spinner options. How do I remove those radio buttons so that just the option text remains?
+2
A:
Hi!
If you want to get rid of radio buttons on the spinner list you have to provide your own layout for row.
Take a look at the example below:
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);
}
}
}
The custom layout for spinner row is just a simple LinearLayout with one TextView element which id is "text" (android:id="@+id/text")
This is just simple example. If you need more fancy layout than just TextView you would probably have to override getView() method of MySpinnerAdapter.
Ramps
2009-12-13 18:46:19
A:
hi its posible to put one radio button on right side in spinner list in custom spinner xml
Dhaiwat
2010-09-29 07:25:17