All;
I am making an android application that I need to adjust an image if in the backend a variable is true or false. When the user adds a new ParseObject, I automatically set the wasBillPaid to false.
This creates a Boolean column in my Parse.com backend.
Here is some code.
When the adapter is loaded, I want to check if the Boolean is T or 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);
}
Now, I already now the error here. The ParseConstrants.KEY_CREDITOR_BILL_PAID holds the value as a string. This is from the ParseConstrants class.
public static final String KEY_CREDITOR_BILL_PAID = "wasBillPaid";
I have two icons overlapping. When the activity loads, I want to check to see what the wasBillPaid variable if its true or false. When you tap the ImageView you control the outcome of what is loading in Parse.com
The below code as onClickListeners and they adjust the ParseConstrant to either true or false depending on what icon is pressed. What am I missing here? When I tap the button, it is not updating the backend in 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);
}
});
Also, this is in the error log when I click on the button.
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)
if (ParseConstants.KEY_CREDITOR_BILL_PAID.equals(true)){
error is because of this you are comparing String
with boolean
I think it should be like this
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);
}
}