因此,我有一個不同種類的單元格的列表以及應該放入其中的內容。我試圖加載每一個,但我的適配器只會加載這麼多,然後重複這些單元格。這裏是我的適配器類重複單元格的多個單元格類型的列表適配器
public class FormCellAdapter extends ArrayAdapter<Cell> {
private final Context context;
private static class ViewHolder {
// All cells
TextView questionLabel;
// Checkbox cell
LinearLayout checkGroup;
// Date cell
Button dateButton;
// Dropdown cell
Spinner spinner;
// Slider cell
SeekBar seekBar;
TextView sliderLabel;
// Text area cell
EditText textArea;
// Dropdown cell, text field cell, text field toggle cell
EditText textField;
// Text field toggle cell, toggle cell
RadioGroup radioGroup;
}
public FormCellAdapter(Context context, ArrayList<Cell> cells) {
super(context, 0, cells);
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Cell cell = getItem(position);
final int layout = cell.getLayoutFile();
final CellType type = cell.getCellType();
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(layout, parent, false);
viewHolder.questionLabel = (TextView) convertView.findViewById(R.id.questionTextLabel);
viewHolder.questionLabel.setText(cell.getQuestion());
switch (type) {
case CHECKBOX:
viewHolder.checkGroup = (LinearLayout) convertView.findViewById(R.id.checkGroup);
break;
case DATE:
viewHolder.dateButton = (Button) convertView.findViewById(R.id.dateButton);
break;
case DROPDOWN:
viewHolder.spinner = (Spinner) convertView.findViewById(R.id.spinner);
viewHolder.textField = (EditText) convertView.findViewById(R.id.textField);
break;
case SLIDER:
viewHolder.seekBar = (SeekBar) convertView.findViewById(R.id.seekbar);
viewHolder.sliderLabel = (TextView) convertView.findViewById(R.id.sliderLabel);
break;
case TEXTAREA:
viewHolder.textArea = (EditText) convertView.findViewById(R.id.textArea);
break;
case TEXTFIELD:
viewHolder.textField = (EditText) convertView.findViewById(R.id.textField);
break;
case TEXTFIELDTOGGLE:
viewHolder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup);
viewHolder.textField = (EditText) convertView.findViewById(R.id.textField);
case TOGGLE:
viewHolder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup);
break;
}
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
// This will be filled in later, populating the labels and whatever else needs done.
switch (type) {
case CHECKBOX:
break;
case DATE:
break;
case DROPDOWN:
break;
case SLIDER:
break;
case TEXTAREA:
break;
case TEXTFIELD:
break;
case TEXTFIELDTOGGLE:
case TOGGLE:
break;
}
return convertView;
}
}
我已經修剪了很多代碼,因爲我想我可能剛剛重新開始。在它隨機挑選細胞進入之前,往往會在頂部的細胞在向下滾動然後備份後會有所不同。
任何想法,爲什麼我沒有看到我的所有細胞在這裏,以及他們爲什麼重複自己?
它已經回到了正確數量的細胞,只是沒有正確的單元格。無論如何,這個方法在超級方面得到了照顧。 –
哦,我誤解了你的問題。 –