Android retrieve image from parse.com and use it -


actually, want use library"aphid-flipview-library"to animation of flipping. images want flip parse.com. got problems when doing this. please give me instruction.thanks!

first, create class set , image's bitmap value.

package com.example.bookard;  import android.graphics.bitmap;  public class useforflip {     private bitmap photo;       public bitmap getphoto(){return photo;}      public void setphoto(bitmap photo){photo = photo;}  } 

and, code below first half of rotate activity. want retrieve image parse.com , add arraylist called "notes". arraylist used in second half of rotate activity.

public class rotate extends activity {         useforflip forflip;     @override     protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);          setcontentview(r.layout.rotate);          forflip = new useforflip();          parsequery<parseobject> query = new parsequery<parseobject>("card");          query.getinbackground("wxybhhrlhz", new getcallback<parseobject>() {               @override              public void done(parseobject object, parseexception e) {                  // todo auto-generated method stub                  parsefile fileobject1 = (parsefile) object.get("photoin1");                  fileobject1.getdatainbackground(new getdatacallback(){                       @override                      public void done(byte[] data, parseexception e) {                          // todo auto-generated method stub                          forflip.setphoto(bitmapfactory.decodebytearray(data, 0,data.length));                      }                  });              }          });                arraylist<bitmap> notes = new arraylist<bitmap>();              notes.add(forflip.getphoto());               flipviewcontroller flipview = new flipviewcontroller(this, flipviewcontroller.horizontal);               flipview.setadapter(new noteviewadapter(this, notes));               setcontentview(flipview);      } 

the below code second half of rotate activity.

public class noteviewadapter extends baseadapter {     private layoutinflater inflater;             private arraylist<bitmap> notes;      public noteviewadapter(context currentcontext, arraylist<bitmap> allnotes) {         inflater = layoutinflater.from(currentcontext);                 notes = allnotes;     }      @override     public int getcount() {         return notes.size();     }      @override     public object getitem(int position) {         return position;     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {         view layout = convertview;          if (convertview == null) {             layout = inflater.inflate(r.layout.rotate, null);         }                       bitmap note = notes.get(position);          imageview tview = (imageview) layout.findviewbyid(r.id.picture);          tview.setimagebitmap(note);          return layout;     } } 

i run code, there's nothing in tview.

the thing can't figure out how can put image parse.com arraylist

you need move part inside callback.

     parsequery<parseobject> query = new parsequery<parseobject>("card");      query.getinbackground("wxybhhrlhz", new getcallback<parseobject>() {           @override          public void done(parseobject object, parseexception e) {              // todo auto-generated method stub              parsefile fileobject1 = (parsefile) object.get("photoin1");              fileobject1.getdatainbackground(new getdatacallback(){                   @override                  public void done(byte[] data, parseexception e) {                      // todo auto-generated method stub                      if(e == null){                          bitmap bmp1 = bitmapfactory.decodebytearray(data, 0,data.length);                              ddd.setphoto(bmp1);                          imageview img=(imageview)findviewbyid(r.id.xxx);                          img.setimagebitmap(ddd.getphoto());                      }else{                          log.d("test","there problem downloading data.");                      }                  }               });          }      });      } 

as can see, there's no need use ddd class.

alternative solution: use <com.parse.parseimageview>. usage pretty straightforward, i.e.:

parseimageview view = (parseimageview) findviewbyid(r.id.parse); parsefile fileobject1 = ... //file query view.setparsefile(fileobject1); view.loadinbackground(); 

based on edit, i'd suggest:

@override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      setcontentview(r.layout.rotate);      flipviewcontroller flipview = new flipviewcontroller(this, flipviewcontroller.horizontal);      noteviewadapter madapter = new noteviewadapter(this);      flipview.setadapter(madapter);      setcontentview(flipview); //why calling setcontentview twice?       arraylist<bitmap> notes = new arraylist<bitmap>();       parsequery<parseobject> query = new parsequery<parseobject>("card");      query.getinbackground("wxybhhrlhz", new getcallback<parseobject>() {           @override          public void done(parseobject object, parseexception e) {              parsefile fileobject1 = (parsefile) object.get("photoin1");              fileobject1.getdatainbackground(new getdatacallback(){                   @override                  public void done(byte[] data, parseexception e) {                      notes.add(bitmapfactory.decodebytearray(data,0,data.length));                      madapter.setnotes(notes);                  }              });          }      });      } 

then create method inside adapter:

public void setnotes(arraylist notes) {     this.notes = notes;     notifydatasetchanged(); } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -