Reputation: 365
I am trying to populate a spinner but I seem to be missing something in my layout file
ArrayAdapter<String> cuisines = new ArrayAdapter<String>(this, R.layout.spinner_view,
getResources().getStringArray(R.array.cuisines));
I can't find R.layout.spinner_view and can only assume that I have to make it myself in my layout file. How do I do that?
Upvotes: 1
Views: 3094
Reputation: 40406
Use import com.companyname.product.R;
instead of
import android.R;
Upvotes: 2
Reputation: 29199
If you want to load with default spinner view, then use,
ArrayAdapter<String> cuisines = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.cuisines));
Upvotes: 1
Reputation: 7888
Include spinner in xml file as:
<Spinner
android:id="@+id/spin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
and in activity:
Spinner spinner=(Spinner) findViewById(R.id.spin);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_spinner_item,R.array.cuisines);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Upvotes: 3