Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.R.simple_spinner_adapter cannot be resolved

Android 2.3.3

I am having a Spinner in my xml file and I wish to set an ArrayList as a source. I am trying to instantiate the ArrayAdapter with the ArrayList, but i don't get the R.simple_spinner_adapter to select.

Here is the code :::

public class UnitConverter extends Activity{


    Spinner spnUnit;
    ArrayAdapter<String> ad;

    ArrayList<String> alAngle = new ArrayList<String>();



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.unitconverter);

        spnUnit = (Spinner) findViewById(R.id.spinnerUnit);
        ad = new ArrayAdapter<String>(this, android.R.simple_spinner_adapter, alAngle);
    // Error at above line near android.R.simple_spinner_adapter    
        setDataToArrayLists();



    }
like image 238
Vamsi Challa Avatar asked Nov 03 '22 05:11

Vamsi Challa


1 Answers

The ans to ur question is u are not using adapter properly:-

android.R.simple_spinner_adapter should be android.R.layout.simple_spinner_item

Sample to this can be:-

Spinner  spinner = (Spinner) findViewById(R.id.font_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.font_array,android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

check using as above this is sample used in my code...!!!!

like image 174
Ruchit Shah Avatar answered Nov 11 '22 12:11

Ruchit Shah