How to install an adapter for a spinner

how to configure adapter on spinner if i have ArrayList<HashMap<String, String>> classesList that contine information that i will show it

What is the correct type of adapter that I should use

+4
source share
3 answers

ArrayAdapter should work. Try with the string [].

 Spinner s = null; final String[] choices = {"1","2"}; ArrayAdapter<String> a =new ArrayAdapter<String>(ObservationSubmit.this,android.R.layout.simple_spinner_item, choices); a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(a); 
+5
source
  String[] arraySpinner = new String[] { "1", "2", "3", "4", "5", "6", "7" }; Spinner s = (Spinner) findViewById(R.id.Spinner01); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arraySpinner); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(adapter); 
0
source
 import android.content.Context; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import com.agreeta.firebasedatabasedemo.R; import java.util.ArrayList; import java.util.HashMap; public class TestAdapter extends ArrayAdapter { private Context mContext; private ArrayList<HashMap<String, String>> hashMapArrayList = new ArrayList<>(); public TestAdapter(@NonNull Context context, ArrayList<HashMap<String, String>> list) { super(context, 0 , list); mContext = context; hashMapArrayList = list; } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { View listItem = convertView; if(listItem == null) listItem = LayoutInflater.from(mContext).inflate(R.layout.like_row,parent,false); TextView release = (TextView) listItem.findViewById(R.id.tv_title); release.setText(hashMapArrayList.get(position).get("key")); return listItem; } } 

Try with this example. Here, the "key" is the HashMap key, with which you can set the value for the counter line.

0
source

Source: https://habr.com/ru/post/1445095/


All Articles