Java 使用ListView适配器中的复选框分析JSONObject中的布尔值

Java 使用ListView适配器中的复选框分析JSONObject中的布尔值,java,android,json,android-studio,Java,Android,Json,Android Studio,我有一个JSONObject,里面有布尔值和不同的字符串,看起来非常像这样 {"1c1":false,"1c2":false,"1c3":false,"1c4":false,"1ed1":false,"1ed2":false,"1ed3":false,"1ep1":true,"2c1":true,"2c2":true,"2c3":false,"2ed1":false,"2ed2":false,"2ed3":true} 每个ListView项都有一个值,该值至少等于JSONObject中的一个字

我有一个JSONObject,里面有布尔值和不同的字符串,看起来非常像这样

{"1c1":false,"1c2":false,"1c3":false,"1c4":false,"1ed1":false,"1ed2":false,"1ed3":false,"1ep1":true,"2c1":true,"2c2":true,"2c3":false,"2ed1":false,"2ed2":false,"2ed3":true}
每个ListView项都有一个值,该值至少等于JSONObject中的一个字符串

ChecklistAdapter.java

public class ChecklistAdapter extends ArrayAdapter<Record> {



public ChecklistAdapter(Context context) {
    super(context, R.layout.checklist_item);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.checklist_item, parent, false);

    }

        TextView desc = (TextView) convertView.findViewById(R.id.textView9);
        CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);

        final JSONObject fetchedJSON = ParseUser.getCurrentUser().getJSONObject("checklistData");
        final Record dataRecord = getItem(position);

        desc.setText(dataRecord.getValue());

        final JSONObject myObject = new JSONObject();



    // if item id in list view is equal to one of the strings in the json object make sure the checkbox is selected as true


    checkBox.setOnClickListener(new View.OnClickListener() {

        String idSelected = dataRecord.getID();

        public void onClick(View v) {
            if (((CheckBox) v).isChecked()) {

                ParseUser.getCurrentUser().put("checklistData", myObject);
                ParseUser.getCurrentUser().saveInBackground();

                Toast.makeText(getContext(), idSelected,
                        Toast.LENGTH_SHORT).show();

            } else {

                Toast.makeText(getContext(), "CheckBox is unchecked",
                        Toast.LENGTH_SHORT).show();

            }
        }
    });

    return convertView;

        }

        public void swapImageRecords(List<Record> objects) {
            clear();

            for (Record object : objects) {
                add(object);
            }

            notifyDataSetChanged();

        }

    }

我的计划是,若“idSelected”等于JSONObject中的一个字符串,则检查它是否为true或false布尔值,并将复选框选为true值。

我不确定您是否需要有关布尔值的帮助,或者是否需要将状态同步到
复选框

对于布尔值,您可以在JSONObject上使用
getBoolean()
方法来接收Java布尔值。下面是文档的链接


谢谢!我会看一下文档,看看我能做些什么来同步复选框的状态
String idSelected = dataRecord.getID();