Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在listview适配器中设置复选框状态_Android - Fatal编程技术网

Android 在listview适配器中设置复选框状态

Android 在listview适配器中设置复选框状态,android,Android,我有几个复选框,当用户建造一辆汽车时选中。然后在我的listview适配器中,我试图解释这一点。下面是我的代码,我不认为setText适用于复选框 这是我的错误: android.content.res.Resources$NotFoundException: String resource ID #0x1 at android.content.res.Resources.getText(Resources.java:274) at android.widget.TextView.setText

我有几个复选框,当用户建造一辆汽车时选中。然后在我的listview适配器中,我试图解释这一点。下面是我的代码,我不认为setText适用于复选框

这是我的错误:

android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.Resources.getText(Resources.java:274)
at android.widget.TextView.setText(TextView.java:4122)
以下是我的listview适配器代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    ViewHolder holder;
    if(v == null) {
        v = mInflater.inflate(R.layout.list_item_car, parent, false);
        holder = new ViewHolder();
        holder.txtMake = (TextView) v.findViewById(R.id.txt_make);
        holder.txtModel = (TextView) v.findViewById(R.id.txt_model);
        holder.c1 = (CheckBox) v.findViewById(R.id.c1);
        holder.c2 = (CheckBox) v.findViewById(R.id.c2);



        v.setTag(holder);
    }
    else {
        holder = (ViewHolder) v.getTag();
    }

    // fill row data
    Car currentItem = getItem(position);
    if(currentItem != null) {
        holder.txtMake.setText(currentItem.getMake());
        holder.txtModel.setText(currentItem.getModel());
        holder.c1.setText(currentItem.getc1());  //<--error here
        holder.c2.setText(currentItem.getc2());  //<--error here
    }

    return v;
}
如日志所示:

资源$NotFoundException:字符串资源ID 0x1

可能是getc1和getc2方法返回int类型的值,所以系统将这两个值都视为id,并尝试在资源中查找值

使用String.valueOf方法在复选框中将int值显示为文本:

    holder.txtMake.setText(String.valueOf(currentItem.getMake()));
    holder.txtModel.setText(String.valueOf(currentItem.getModel()));
    holder.c1.setText(String.valueOf(currentItem.getc1()));  
    holder.c2.setText(String.valueOf(currentItem.getc2()));