Parse.com布尔语句

时间:2016-01-06 04:01:58

标签: android parse-platform

所有

我正在创建一个Android应用程序,如果在后端变量为true或false,我需要调整图像。当用户添加新的ParseObject时,我会自动将wasBillPaid设置为false。

这会在我的Parse.com后端创建一个布尔列。

这是一些代码。

当加载适配器时,我想检查布尔值是T还是F.

        if (ParseConstants.KEY_CREDITOR_BILL_PAID.equals(true)){
            holder.billPaid.setVisibility(View.VISIBLE);
            holder.billNotPaid.setVisibility(View.GONE);
        } else {
            holder.billPaid.setVisibility(View.GONE);
            holder.billNotPaid.setVisibility(View.VISIBLE);
        }

现在,我已经在这里犯了错误。 ParseConstrants.KEY_CREDITOR_BILL_PAID将值保存为字符串。这是来自ParseConstrants类。

 public static final String KEY_CREDITOR_BILL_PAID = "wasBillPaid";

我有两个图标重叠。当活动加载时,我想检查isBillPaid变量的真或假。当您点击ImageView时,您可以控制Parse.com中加载内容的结果

以下代码为onClickListeners,他们根据按下的图标将ParseConstrant调整为true或false。我在这里错过了什么?当我点击按钮时,它没有更新Parse.com中的后端

 // What happens when we click on the BILL PAID icon
    holder.billPaid.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ParseQuery<ParseObject> query = ParseQuery.getQuery("Bills");
            query.getInBackground(ParseConstants.KEY_OBJECTID, new GetCallback<ParseObject>() {
                @Override
                public void done(ParseObject parseObject, com.parse.ParseException e) {
                    if(e == null){
                        parseObject.put(ParseConstants.KEY_CREDITOR_BILL_PAID, true);
                        parseObject.saveInBackground();
                    } else {
                        e.printStackTrace();
                    }
                }
            });
            holder.billNotPaid.setVisibility(View.VISIBLE);
            holder.billPaid.setVisibility(View.GONE);
        }
    });

    // What happens when we click on the BILL NOT PAID icon
    holder.billNotPaid.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ParseQuery<ParseObject> query = ParseQuery.getQuery("Bills");
            query.getInBackground(ParseConstants.KEY_OBJECTID, new GetCallback<ParseObject>() {
                @Override
                public void done(ParseObject parseObject, com.parse.ParseException e) {
                    if(e == null){
                        parseObject.put(ParseConstants.KEY_CREDITOR_BILL_PAID, false);
                        parseObject.saveInBackground();
                    } else {
                        e.printStackTrace();
                    }
                }
            });
            holder.billPaid.setVisibility(View.VISIBLE);
            holder.billNotPaid.setVisibility(View.GONE);
        }
    });

此外,当我点击按钮时,这是在错误日志中。

01-05 23:03:17.931   9266-20636/net.pixeledstudio.bethink I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
01-05 23:03:17.951   9266-20636/net.pixeledstudio.bethink I/System.out﹕ KnoxVpnUidStorageknoxVpnSupported API value returned is false
01-05 23:03:18.141    9266-9266/net.pixeledstudio.bethink W/System.err﹕ com.parse.ParseException: no results found for query
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at com.parse.AbstractQueryController$1.then(AbstractQueryController.java:34)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at com.parse.AbstractQueryController$1.then(AbstractQueryController.java:25)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$14.run(Task.java:798)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.completeImmediately(Task.java:789)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.access$000(Task.java:32)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$10.then(Task.java:581)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$10.then(Task.java:578)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.runContinuations(Task.java:875)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.trySetResult(Task.java:913)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.TaskCompletionSource.trySetResult(TaskCompletionSource.java:39)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.TaskCompletionSource.setResult(TaskCompletionSource.java:62)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$15$1.then(Task.java:856)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$15$1.then(Task.java:843)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$14.run(Task.java:798)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.completeImmediately(Task.java:789)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.continueWith(Task.java:588)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task.continueWith(Task.java:599)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at bolts.Task$15.run(Task.java:843)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-05 23:03:18.151    9266-9266/net.pixeledstudio.bethink W/System.err﹕ at java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:0)

 if (ParseConstants.KEY_CREDITOR_BILL_PAID.equals(true)){

错误是因为您将Stringboolean

进行比较

我认为应该是这样的

public void done(ParseObject parseObject , ParseException e) {
    if(parseObject.getBoolean("<YOUR COLUMN NAME>")){
     holder.billPaid.setVisibility(View.VISIBLE);
        holder.billNotPaid.setVisibility(View.GONE);
    } else {
        holder.billPaid.setVisibility(View.GONE);
        holder.billNotPaid.setVisibility(View.VISIBLE);
    }
}