0

基本上我想要做的是在列表视图的每一行中有 4 个复选框。因为我正在从 web 服务中检索信息,所以我需要将文本设置为复选框。我尝试使用 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;
 }
}
4

1 回答 1

0

两件可能的事情:1)检查你的searchArrayList.get(position).getChoice1(), 等等不仅仅是空字符串“”,而是有真实的文本。

2)确保您的复选框文本具有不同于背景的颜色

于 2013-06-12T08:10:51.120 回答