私はスピナー用のカスタムアダプターを作成しました。スピナーはリストから名前を表示する必要があります。以下は、私のコードです:ここではスピナーが正しいデータを表示していません
empNameList = new ArrayList<HashMap<String, String>>();
JSONArray jsonArray = response.getJSONArray("Salon");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String empName = jsonObject.getString("employeename");
String empId = jsonObject.getString("employee_id");
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("empId", empId);
hashMap.put("empName", empName);
empNameList.add(hashMap);
}
employeeAdapter = new EmployeeAdapter(getApplicationContext(), R.layout.service_list, empNameList);
employeeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(employeeAdapter);
は私のアダプタクラスです:
public class EmployeeAdapter extends ArrayAdapter<HashMap<String, String>> {
ArrayList<HashMap<String, String>> arrayList = new ArrayList<HashMap<String, String>>();
Context context;
int layoutResourceId;
HashMap<String, String> hashmap;
public EmployeeAdapter(Context context, int layoutResourceId, ArrayList<HashMap<String, String>> arrayList) {
super(context, layoutResourceId, arrayList);
this.arrayList = arrayList;
this.context = context;
this.layoutResourceId = layoutResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parrent) {
View view = convertView;
final ViewHolder holder;
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(layoutResourceId, parrent, false);
holder = new ViewHolder();
holder.textView42 = (TextView) view.findViewById(R.id.textView42);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
if (position % 2 == 0) {
view.setBackgroundColor(context.getResources().getColor(R.color.pink));
} else {
view.setBackgroundColor(Color.WHITE);
}
hashmap = new HashMap<String, String>();
hashmap = arrayList.get(position);
System.out.println("empName = " + hashmap.get("empName"));
holder.textView42.setText(hashmap.get("empName"));
return view;
}
static class ViewHolder {
TextView textView42;
}
スピナーはempNameListの名前、ハッシュマップを表示していません。どんな助けでも感謝します。
SpinnerがempNameListの名前ではなくハッシュマップを表示しているとはどういう意味ですか? –
スピナーは スニルSangeeta ...... ようなデータを表示しなければならないしかし、それは {のempName =スニル、EMPID = 2} { のempName = sangeeta、EMPID = 3}のような –
データ表示されている ":" - コロン? – Prabs