基本上我要做的是在listview的每一行中有4个复选框。因为我正在从webservice中检索信息,所以我需要将文本设置为复选框。我尝试使用textview,它设法工作。因此,这意味着我对复选框的编码有问题。谁能告诉我哪里出错了?谢谢。
这是我为baseadapter编写的代码,但这段代码将导致强制关闭。
public class BaseAdapter extends BaseAdapter {
private static ArrayList<Result> searchArrayList;
private LayoutInflater mInflater;
public BaseAdapter(Context context,ArrayList<Result> result) {
searchArrayList = result;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtQn = (TextView) convertView.findViewById(R.id.question);
holder.txtC1 = (CheckBox) convertView.findViewById(R.id.choice1);
holder.txtC2 = (CheckBox) convertView.findViewById(R.id.choice2);
holder.txtC3 = (CheckBox) convertView.findViewById(R.id.choice3);
holder.txtC4 = (CheckBox) convertView.findViewById(R.id.choice4);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtQn.setText(searchArrayList.get(position).getQuestion());
holder.txtC1.setText(searchArrayList.get(position).getChoice1());
holder.txtC2.setText(searchArrayList.get(position).getChoice2());
holder.txtC3.setText(searchArrayList.get(position).getChoice3());
holder.txtC4.setText(searchArrayList.get(position).getChoice4());
return convertView;
}
static class ViewHolder {
TextView txtQn;
CheckBox txtC1;
CheckBox txtC2;
CheckBox txtC3;
CheckBox txtC4;
}
}
答案 0 :(得分:0)
两件事:
1)检查您的searchArrayList.get(position).getChoice1()
等不仅仅是空字符串“”,而且还有真实的文本。
2)确保您的复选框文字为different color other than the background。