【问题标题】:More than one checkbox in listview row列表视图行中的多个复选框
【发布时间】:2013-06-12 07:46:30
【问题描述】:

基本上我要做的是在列表视图的每一行内有 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;
 }
}

【问题讨论】:

  • 发布 logcat 输出

标签: android listview checkbox


【解决方案1】:

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

2) 确保您的复选框文本包含different color other than the background

【讨论】:

  • 谢谢!设法以某种方式解决它。也感谢您的提醒(:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
  • 2015-02-24
相关资源
最近更新 更多