I have problem with nested query. In query5.whereEqualTo("piwo", followList2.get(0))
I want to get the object, but it spits error that followList2 needs to be declared final, but when it does all the anonymous class gets in red with Cannot resolve constructor(...)
error. Anyone got this before?
ParseQuery<ParseObject> query3 = ParseQuery.getQuery("Piwo");
query3.whereEqualTo("marka", beer); // TODO if(beer == "all") then don't use it
query3.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> followList2, ParseException e) {
if (followList2 != null) {
Log.d("ASD", "Szukane piwo: " + followList2.get(0).getString("marka"));
} else {
Log.d("ASD", "Zero wyników1");
}
ParseQueryAdapter<ParseObject> adapter =
new ParseQueryAdapter<ParseObject>(this, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery<ParseObject> create() {
// Here we can configure a ParseQuery to our heart's desire.
ParseQuery query5 = new ParseQuery("Cena");
query5.whereContainedIn("lokal", list);
query5.whereEqualTo("piwo", followList2.get(0);
query5.include("piwo");
query5.include("lokal");
query5.orderByAscending("cena");
return query5;
}
});
adapter.setTextKey("lokal.place");
adapter.setImageKey("photo");
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
If I understand you correctly, you already tried:
Which for some reason makes the compiler unhappy.
I think there might be two possible solutions
Solution 1:
Solution 2:
As said in the comments, I cannot recall having had the same problem but I hope this addresses the issue.
A third suggestion would be to try out Bolts https://github.com/BoltsFramework/Bolts-Android (comes with the parse API). In case you are familiar with promises in javascript, Bolts is essentially the same for Java. It removes the need for nesting calls, making a pyramid shaped chunk of code as the amount of depending queries grows. However, it does take some time to get used to, and in the simple cases it is not necessary.
Bonus:
As you have trouble using the text from your include in your adapter, I will show you some of my code as an example.
First, I have a simple layout for an item:
res/layout/view_adapter_item_simple.xml
Next, here is my custom adapter:
NOTICE: We are still not quite there yet. This works similar to the standard ParseQueryAdapter in that it only looks at the columns of the current class using
text.setText(object.getString(textCol))
.However, one could fairly easy write a special purpose adapter to handle the nested include, for example:
Now using the adapter like this:
Where the queryFactory is obligated to do
query.include("lokal")
(includes the whole 'lokal' pointer), or `query.include("lokal.place") (only include the 'place' column of 'lokal');Extra bonus - subclassing
As a final note, it does not look like you are using subclassing, but if you did, you could also have a specialized custom adapter for Cena subclasses.
In this case
cena.getPlace()
could look up the included lokal: