android - View Holder Stability Issue -


i uploading data server, , if data uploaded server showing "saved", can see "uploaded" image.

but issue is, have stored data first item row, whereas getting "saved" text in different row item

holder.textdatastatus.settext(imagelist.get(position).getdata());  protected void onpostexecute(string file_url) {   // dismiss dialog once product deleted   pdialog.dismiss();    try {         // prepare save data        if(strstatusid.equals("0"))        {               toast.maketext(uploadimagesactivity.this, "unable upload", toast.length_short).show();                 }                 else if (strstatusid.equals("1"))                 {                     toast.maketext(uploadimagesactivity.this, "data uploaded successfully", toast.length_short).show();                     imagelist.get(position).setdata("saved");                                    log.d("strdata:", filename); // getting correct tapped item                     madapter.notifydatasetchanged();                 }                 else                 {                     toast.maketext(uploadimagesactivity.this, "unable upload", toast.length_short).show();                 }                  } catch (exception e) {                     // todo: handle exception                 }              if (file_url != null){                 toast.maketext(uploadimagesactivity.this, file_url, toast.length_long).show();            } 

the problem adapter doesn't know data row uploaded server. need tell adapter. question "how tell adapter?", have list imagelist. need edit it.

now, add bool mydata class like: boolean uploaded = false; , create getter setter it.

add following lines getview():

if(imagelist.get(position).isuploaded()){     holder.btnupload.settext("save"); }else{     holder.btnupload.settext("upload"); } 

now, need set value true, after upload done. should uploaddata class. that, need send position uploaddata class. can constructor following:

class uploaddata extends asynctask<string, string, string> {     private progressdialog pdialog;      int position;      //constructor pass position of row, on button clicked class     public uploaddata(int position){         this.position=position;     }       /**     * before starting background thread show progress dialog     * */      .     .     .     .     protected void onpostexecute(string file_url) {        // dismiss dialog once product deleted        pdialog.dismiss();         //after upload done, set value true        imagelist.get(position).setuploaded(true);        //now need notify our adapter can reflect changes        madapter.notifydatasetchanged();     .     . 

now, according current code, think passing value of position uploaddata going tough through constructor. so, can try setting value in global variable in class.

edit 1:

pass position global variable in holder.btndata.setonclicklistener following:

holder.btndata.setonclicklistener(new onclicklistener() {              @suppresswarnings("deprecation")             @override             public void onclick(view v) {                 //pass position activity's global variable                 pos = position/*position adapter*/;                 strpath = imagelist.get(position).getimages().tostring();                 filename = strpath.substring(strpath.lastindexof('/') + 1, strpath.length());                                                        showdialog(dialog_data);              }         }); 

please leave comment if need explanation.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -