如果我有ArrayList<HashMap<String, String>>
个课程列表,如何将适配器设置为微调器
包含我将显示它的信息
我应该使用的正确类型的适配器
答案 0 :(得分:5)
ArrayAdapter应该可以工作。尝试使用字符串[]。
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);
答案 1 :(得分:0)
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);
答案 2 :(得分:0)
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;
}
}
尝试使用此示例。这里的“键”是您的HashMap键,通过它您可以将值设置为微调器的行。