How to set arraylist to turn

Below is my code. But it shows that this is impossible. Can someone please suggest me how to configure arraylist on spinner rather than setting up a simple array for spinner.Below is my code.

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

// Here I have code for setting string values ​​in arraylist

// Below is the code where I am trying to install an arraylist, but it says: ArrayAdapter constructor (new Runnable () {}, int, ArrayList) undefined "

 Spinner spinnerCategory = (Spinner)findViewById(R.id.spinnercategory); ArrayAdapter<String> categoriesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categoryList); 
+4
source share
3 answers

Use the Activity Context as the first parameter of the ArrayAdapter, you can use

ActivityName.this instead of this , where ActivityName is the name of the activity class. You seem to be running this code in some Runnable or Thread classes, so right now this is an instance of the Runnable object.

+3
source

Use the following -

 Spinner spinnerCategory = (Spinner)findViewById(R.id.spinnercategory); ArrayAdapter<String> categoriesAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, categoryList); 
+3
source

Use an adapted adapter and implement it according to your data. This is just a sample of broken code.

  Spinner spinnerCategory = (Spinner)findViewById(R.id.spinnercategory); spinnerCategory.setAdapter( new SpinnerAdapter() { @Override public void unregisterDataSetObserver(DataSetObserver observer) { // TODO Auto-generated method stub } @Override public void registerDataSetObserver(DataSetObserver observer) { // TODO Auto-generated method stub } @Override public boolean isEmpty() { // TODO Auto-generated method stub return false; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } @Override public int getViewTypeCount() { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub return null; } @Override public int getItemViewType(int position) { // TODO Auto-generated method stub return 0; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public int getCount() { // TODO Auto-generated method stub return 0; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub return null; } }); 
+1
source

All Articles