android - ListView with ImageView and TextView, after Scrolling down an Up a random item is set -
i have list imageview , textview. read scann time , specified position of textview has set. done right way, after srolling down , textview in listview set. seeing not new, not solve problem.any idea?? baseadapter in following. tried more week no solution
@override public view getview( final int position, view convertview, viewgroup parent) { if (convertview == null) { log.d("convertview", "nulll"); convertview = layoutinflater.from(mcontenxt).inflate( r.layout.list_items, null); holder = new viewholder(); holder.textview = (textview) convertview .findviewbyid(r.id.placename); holder.imageview = (imageview) convertview .findviewbyid(r.id.itemsymbole); holder.textdate = (textview) convertview .findviewbyid(r.id.txtviewtimeanddate); holder.imagemap = (imageview)convertview.findviewbyid(r.id.imageviewmap); holder.linearlayouttext = ( linearlayout)convertview.findviewbyid(r.id.txtviewlist); holder.linearlayoutimage = ( linearlayout)convertview.findviewbyid(r.id.thumbnail); convertview.settag(holder); } log.d("convertview", "not nullll"); holder = (viewholder) convertview.gettag(); holder.id = position; holder.textview.settext(items.get(position).get("productname")); holder.imageview.setid(position); holder.linearlayouttext.setbackgroundcolor(position); if (items.get(position).get("identifier") .equals(com.metasec.wachmann.itemactivity.uid)) { holder.linearlayouttext.setbackgroundcolor(color.cyan); holder.imageview.setimageresource(r.drawable.ok); log.d("timeeee", itemactivity.scanndateandtime); holder.textdate.settext(itemactivity.scanndateandtime); notifydatasetchanged(); }else { holder.imageview.setimageresource(r.drawable.not_ok); holder.textdate.settext(""); notifydatasetchanged(); } holder.linearlayouttext.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub holder.linearlayouttext.setbackgroundcolor(position); holder.linearlayouttext.setbackgroundcolor(color.red); notifydatasetchanged(); string placename = items.get(position).get("productname"); string identifier = items.get(position).get("identifier"); string itemid = items.get(position).get("itemid"); string propertybaseid = null; string gpscoordinates = null; gpstracker gpstracker = new gpstracker(mcontenxt); gpstracker.stopusinggps(); double latitude = 0; double longitude = 0; if (gpstracker.cangetlocation()) { latitude = gpstracker.getlatitude(); longitude = gpstracker.getlongitude(); gpscoordinates = latitude + ", " + longitude; } (int k = 0; k < loggedactivity.propertybaselist.size(); k++) { if (loggedactivity.propertybaselist.get(k).getname() .equals("xxxxxxx")) { propertybaseid = loggedactivity.propertybaselist.get(k) .getpropertybaseid(); intent intentsenderdatatoserver = new intent(mcontenxt, senderreportdemagetoserveractivity.class); // give itemid intentsenderdatatoserver.putextra(item_id, itemid); // give groupid intentsenderdatatoserver.putextra(product_name, placename); // give groupname intentsenderdatatoserver.putextra(identifier, identifier); // give propertybaseid intentsenderdatatoserver.putextra(property_base_id, propertybaseid); // give gps coordinates intentsenderdatatoserver.putextra(gps_coordinates, gpscoordinates); log.d("items.get(position).get(productnnnnname)", items .get(position).get("productname")); intentsenderdatatoserver.putextra("productname", placename); intentsenderdatatoserver.putextra("identifier", identifier); mcontenxt.startactivity(intentsenderdatatoserver); } // end if loop } // end loop } }); holder.imagemap.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub string placename = items.get(position).get("productname"); string identifier = items.get(position).get("identifier"); string itemid = items.get(position).get("itemid"); log.d("placename11",placename); log.d("identifier111",identifier); log.d("itemid111",itemid); intent intentwachmanmapactivitiy = new intent(mcontenxt, wachmanopenstreetmapviewactivity.class); intentwachmanmapactivitiy.putextra(item_id, itemid); // give groupid intentwachmanmapactivitiy.putextra(product_name, placename); // give groupname intentwachmanmapactivitiy.putextra(identifier, identifier); log.d("items.get(position).get(productnnnnname)", items .get(position).get("productname")); intentwachmanmapactivitiy.putextra("productname", placename); intentwachmanmapactivitiy.putextra("identifier", identifier); mcontenxt.startactivity(intentwachmanmapactivitiy); } }); return convertview; } static class viewholder { textview textview = null; textview textdate = null; checkbox checkbox = null; imageview imageview = null; imageview imagemap = null; imagebutton imagebuttonmap = null; linearlayout linearlayouttext = null; linearlayout linearlayoutimage = null; int id; }
and following class shows own adapter called. backgroudn have call adapter ofter , previous time , figure has remained.
private class sendbackground extends asynctask<void, void, boolean> { @override protected void onpreexecute() { mprogdialog = new progressdialog(getbasecontext()); mprogdialog.setprogressstyle(progressdialog.style_spinner); mprogdialog = progressdialog.show(itemactivity.this, "sending", " please wait" ); } @override protected boolean doinbackground(void... params) { // todo auto-generated method stub return httprequest.postdata(itemidtmp, propertybaseidtmp, uid, coordinatestmp); } @override protected void onpostexecute(boolean result) { log.d("sendbackground", "onpostexecute"); if (result == true) { log.d("onpostexecute", "true"); //mprogressbar.setvisibility(view.gone); mprogdialog.dismiss(); toast.maketext(getapplicationcontext(), "data sent..", toast.length_long).show(); /*----------------------------->>>> whenever server true return oown adapter hast adapted, mentioned state , time of previous items have remained */ //setlistadapter(mybaseadapteritemactivity); listview.setadapter(mybaseadapteritemactivity); mybaseadapteritemactivity.notifydatasetchanged(); } else { mprogdialog.dismiss(); toast.maketext(getapplicationcontext(), "sending data server failed", toast.length_long) .show(); } } }
// read comments write need modifiaction // not call notifiy dataset change inside adapter. // if not work write sample code
@override public view getview( final int position, view convertview, viewgroup parent) { viewholder holder = null; // use if (convertview == null) { log.d("convertview", "nulll"); convertview = layoutinflater.from(mcontenxt).inflate( r.layout.list_items, null); holder = new viewholder(); holder.textview = (textview) convertview .findviewbyid(r.id.placename); holder.imageview = (imageview) convertview .findviewbyid(r.id.itemsymbole); holder.textdate = (textview) convertview .findviewbyid(r.id.txtviewtimeanddate); holder.imagemap = (imageview)convertview.findviewbyid(r.id.imageviewmap); holder.linearlayouttext = ( linearlayout)convertview.findviewbyid(r.id.txtviewlist); holder.linearlayoutimage = ( linearlayout)convertview.findviewbyid(r.id.thumbnail); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); // new changes log.d("convertview", "not nullll"); } holder.id = position; holder.textview.settext(items.get(position).get("productname")); holder.imageview.setid(position); // why set position cause error //holder.linearlayouttext.setbackgroundcolor(position); if (items.get(position).get("identifier") .equals(com.metasec.wachmann.itemactivity.uid)) { holder.linearlayouttext.setbackgroundcolor(color.cyan); holder.imageview.setimageresource(r.drawable.ok); log.d("timeeee", itemactivity.scanndateandtime); holder.textdate.settext(itemactivity.scanndateandtime); // notifydatasetchanged(); no need call it. }else { holder.imageview.setimageresource(r.drawable.not_ok); holder.linearlayouttext.setbackgroundcolor(color.green); holder.textdate.settext(""); //notifydatasetchanged(); no need call it. } holder.linearlayouttext.settag(position); holder.linearlayouttext.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // holder.linearlayouttext.setbackgroundcolor(position); holder.linearlayouttext.setbackgroundcolor(color.red); // notifydatasetchanged(); int selectedposition = (integer)v.gettag(); string placename = items.get(selectedposition).get("productname"); string identifier = items.get(selectedposition).get("identifier"); string itemid = items.get(selectedposition).get("itemid"); string propertybaseid = null; string gpscoordinates = null; gpstracker gpstracker = new gpstracker(mcontenxt); gpstracker.stopusinggps(); double latitude = 0; double longitude = 0; if (gpstracker.cangetlocation()) { latitude = gpstracker.getlatitude(); longitude = gpstracker.getlongitude(); gpscoordinates = latitude + ", " + longitude; } // starting activity in lop dangerous because // launching many activity. // should pass array // not know requirement. (int k = 0; k < loggedactivity.propertybaselist.size(); k++) { if (loggedactivity.propertybaselist.get(k).getname() .equals("xxxxxxx")) { propertybaseid = loggedactivity.propertybaselist.get(k) .getpropertybaseid(); intent intentsenderdatatoserver = new intent(mcontenxt, senderreportdemagetoserveractivity.class); // give itemid intentsenderdatatoserver.putextra(item_id, itemid); // give groupid intentsenderdatatoserver.putextra(product_name, placename); // give groupname intentsenderdatatoserver.putextra(identifier, identifier); // give propertybaseid intentsenderdatatoserver.putextra(property_base_id, propertybaseid); // give gps coordinates intentsenderdatatoserver.putextra(gps_coordinates, gpscoordinates); log.d("items.get(position).get(productnnnnname)", items .get(position).get("productname")); intentsenderdatatoserver.putextra("productname", placename); intentsenderdatatoserver.putextra("identifier", identifier); mcontenxt.startactivity(intentsenderdatatoserver); } // end if loop } // end loop } }); holder.imagemap.settag(postion); holder.imagemap.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub int selectedposition = (integer)v.gettag(); string placename = items.get(selectedposition).get("productname"); string identifier = items.get(selectedposition).get("identifier"); string itemid = items.get(selectedposition).get("itemid"); log.d("placename11",placename); log.d("identifier111",identifier); log.d("itemid111",itemid); intent intentwachmanmapactivitiy = new intent(mcontenxt, wachmanopenstreetmapviewactivity.class); intentwachmanmapactivitiy.putextra(item_id, itemid); // give groupid intentwachmanmapactivitiy.putextra(product_name, placename); // give groupname intentwachmanmapactivitiy.putextra(identifier, identifier); log.d("items.get(position).get(productnnnnname)", items .get(position).get("productname")); intentwachmanmapactivitiy.putextra("productname", placename); intentwachmanmapactivitiy.putextra("identifier", identifier); mcontenxt.startactivity(intentwachmanmapactivitiy); } }); return convertview; } static class viewholder { textview textview = null; textview textdate = null; checkbox checkbox = null; imageview imageview = null; imageview imagemap = null; imagebutton imagebuttonmap = null; linearlayout linearlayouttext = null; linearlayout linearlayoutimage = null; int id; }
Comments
Post a Comment