android - parse.com - Nested query and Join Table -


i have problem nested query. in query5.whereequalto("piwo", followlist2.get(0)) want object, spits error followlist2 needs declared final, when anonymous class gets in red cannot resolve constructor(...) error. got before?

parsequery<parseobject> query3 = parsequery.getquery("piwo");                     query3.whereequalto("marka", beer); // todo if(beer == "all") don't use                     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 can configure parsequery 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 understand correctly, tried:

... public void done(final list<parseobject> followlist2, parseexception e) { ... 

which reason makes compiler unhappy.

i think there might 2 possible solutions

  1. if plan use followlist2 objects elsewhere in activity/fragment. declare field variable hold result , read instead. way anonymous inner class should have access it.
  2. write followlist2 local variable declared final. way not altering signature of done() callback.

solution 1:

list<parseobject> mfollowlist2; // field variable outside method ... public void done(list<parseobject> followlist2, parseexception e) {     mfollowlist2 = followlist2;      // use mfollowlist2 in rest of code ...     

solution 2:

public void done(list<parseobject> followlist2, parseexception e) {     final list<parseobject> finalfollowlist2 = followlist2;      // use finalfollowlist2 in rest of code ...     

as said in comments, cannot recall having had same problem hope addresses issue.

a third suggestion try out bolts https://github.com/boltsframework/bolts-android (comes parse api). in case familiar promises in javascript, bolts same java. removes need nesting calls, making pyramid shaped chunk of code amount of depending queries grows. however, take time used to, , in simple cases not necessary.

bonus:

as have trouble using text include in adapter, show of code example.

first, have simple layout item: res/layout/view_adapter_item_simple.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_margin="5dp"     android:background="?android:attr/activatedbackgroundindicator"     android:paddingtop="5dp">      <textview         android:id="@+id/text"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:text="item" />   </relativelayout> 

next, here custom adapter:

public class simpleparseadapter<t extends parseobject> extends         parsequeryadapter<t> {      private static final string tag = simpleparseadapter.class.getsimplename();      private final string textcol;      public simpleparseadapter(context context, string textcol,             queryfactory<t> queryfactory) {         super(context, queryfactory);         this.textcol = textcol;     }      textview text;      @override     public view getitemview(t object, view v, viewgroup parent) {          if (v == null) {             v = view.inflate(getcontext(), r.layout.view_adapter_item_simple,                     null);         }          super.getitemview(object, v, parent);          text = (textview) v.findviewbyid(r.id.text);          text.settext(object.getstring(textcol));          return v;      }   } 

notice: still not quite there yet. works similar standard parsequeryadapter in looks @ columns of current class using text.settext(object.getstring(textcol)).

however, 1 easy write special purpose adapter handle nested include, example:

public class simpleparseincludeadapter<t extends parseobject> extends         parsequeryadapter<t> {      private static final string tag = simpleparseincludeadapter.class.getsimplename();      private final string includecol;     private final string textcol;      public simpleparseincludeadapter(context context, string includecol, string textcol,             queryfactory<t> queryfactory) {         super(context, queryfactory);         this.includecol = includecol;         this.textcol = textcol;     }      textview text;      @override     public view getitemview(t object, view v, viewgroup parent) {          if (v == null) {             v = view.inflate(getcontext(), r.layout.view_adapter_item_simple,                     null);         }          super.getitemview(object, v, parent);          text = (textview) v.findviewbyid(r.id.text);          text.settext(object.getparseobject(includecol).getstring(textcol));          return v;      }   } 

now using adapter this:

new simpleparseincludeadapter(**context**, "lokal", "place",**queryfactory**);  

where queryfactory obligated query.include("lokal") (includes whole 'lokal' pointer), or `query.include("lokal.place") (only include 'place' column of 'lokal');

extra bonus - subclassing

as final note, not using subclassing, if did, have specialized custom adapter cena subclasses.

public class cenaparseadapter extends         parsequeryadapter<cena> {      private static final string tag = cenaparseadapter.class.getsimplename();        public cenaparseadapter(context context,              queryfactory<cena> queryfactory) {         super(context, queryfactory);      }      textview text;      @override     public view getitemview(cena cena, view v, viewgroup parent) {          if (v == null) {             v = view.inflate(getcontext(), r.layout.view_adapter_item_simple,                     null);         }          super.getitemview(object, v, parent);          text = (textview) v.findviewbyid(r.id.text);          text.settext(cena.getplace());          return v;      }   } 

in case cena.getplace() included lokal:

// inside cena sublass  public lokal getlokal() { // assuming lokal subclassed     return (lokal)getparseobject("lokal"); }  public string getplace() {     return (getlokal() != null) ? getlokal().getplace() : ""; }  // inside lokal subclass  public string getplace() {     return getstring("place"); } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -