0
我實現了一個ArrayAdapter
我ListView
:獲取Spinner的一個ListView的位置,並得到其選擇的價值
public class CalcAMRListAdapter extends ArrayAdapter<AMRStateListEntry> implements OnItemSelectedListener {
public CalcAMRListAdapter(Context context, List<AMRStateListEntry> entries) {
super(context, R.layout.activity_calc_amr_fragment_row, entries);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AMRStateListEntry entry = this.getItem(position);
ViewHolder viewHolder = null;
LayoutInflater inflater = null;
if(convertView == null) {
viewHolder = new ViewHolder();
inflater = LayoutInflater.from(this.getContext());
convertView = inflater.inflate(R.layout.activity_calc_amr_fragment_row, parent, false);
viewHolder.spinnerActivity = (Spinner) convertView.findViewById(R.id.calc_amr_row_spinner_activity);
viewHolder.spinnerHours = (Spinner) convertView.findViewById(R.id.calc_amr_row_spinner_hours);
viewHolder.textViewPal = (TextView) convertView.findViewById(R.id.calc_amr_row_textview_pal);
viewHolder.imageButtonDelete = (ImageButton) convertView.findViewById(R.id.calc_amr_row_button_delete);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String pal = null;
switch (entry.getActivity()) {
case 1: pal = "" + 0.95;
break;
case 2: pal = "" + 1.2;
break;
case 3: pal = "" + 1.5;
break;
case 4: pal = "" + 1.7;
break;
case 5: pal = "" + 1.9;
break;
case 6: pal = "" + 2.4;
break;
default: pal = "";
break;
}
viewHolder.spinnerActivity.setSelection(entry.getActivity());
viewHolder.spinnerActivity.setOnItemSelectedListener(this);
viewHolder.spinnerHours.setSelection(entry.getHour());
viewHolder.spinnerHours.setOnItemSelectedListener(this);
viewHolder.textViewPal.setText(pal);
viewHolder.imageButtonDelete.setImageResource(R.drawable.ic_remove_row);
return convertView;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}
private static class ViewHolder {
Spinner spinnerActivity = null;
Spinner spinnerHours = null;
TextView textViewPal = null;
ImageButton imageButtonDelete = null;
}
}
正如你所看到的我ListView
每個項目包含兩個Spinner
。在onItemSelected
方法中,我現在需要獲取ListView
中行的位置,其中Spinner
用於選擇一個值,我還需要在一行中的兩個spinners之間有所不同。我的數據模型是AMRStateListEntry
。我需要在我的AMRStateListEntry
中設置旋鈕的選定值。
我該怎麼做?
可能重複做同樣的[你怎麼Spinner的選擇的價值?(http://stackoverflow.com/questions/2652414/how-do-you-得到選定的價值的微調) – Sufian 2014-12-02 11:53:14
我不能看到我可以從您發佈的鏈接在lisview中的行的位置。我知道我是如何得到一個微調器的價值,但首先我需要從列表視圖中正確的行得到正確的微調。 – Mulgard 2014-12-02 12:02:08