java - EditText Value is same as that of the first row in ListView -
java - EditText Value is same as that of the first row in ListView -
edittext - holder.ednum.settext
setting same value both first item , lastitem(fourth) in listview ex if press plus icon first row in listview (please refer image) value gets changed first item lastly item in listview. has holder.ednum, i'm unsure on how prepare issue.
please see screenshot perfect thought of problem:
bundle com.freshmenu.mylistview; import java.util.list; import android.app.activity; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.edittext; import android.widget.imagebutton; import android.widget.imageview; import android.widget.textview; import com.pavan.mylistview.r; public class customadapter extends baseadapter { public int max_range = 9; public int min_range = 0; int initialvalues = 0; string filepath = "/storage/sdcard0/freshgrub/"; string filepath1 = "/item.jpg"; int initialvalues2 = 0; int pos; context context; rowitem row_pos; list<rowitem> rowitems; rowitem selectedrowitem; customadapter( context context , list<rowitem> rowitems ) { this.context = context; this.rowitems = rowitems; } @override public int getcount() { homecoming rowitems.size(); } @override public object getitem( int position ) { homecoming rowitems.get( position ); } @override public long getitemid( int position ) { homecoming rowitems.indexof( getitem( position ) ); } /* private view holder class */ public class viewholder { imageview profile_pic; textview member_name; textview status; textview contacttype; imagebutton plus; imagebutton minus; edittext ednum; } @override public view getview( int position , view convertview , viewgroup parent ) { final viewholder holder; layoutinflater minflater = ( layoutinflater ) context.getsystemservice( activity.layout_inflater_service ); if ( convertview == null ) { convertview = minflater.inflate( r.layout.list_item , null ); holder = new viewholder(); holder.member_name = ( textview ) convertview.findviewbyid( r.id.member_name ); holder.profile_pic = ( imageview ) convertview.findviewbyid( r.id.profile_pic ); holder.status = ( textview ) convertview.findviewbyid( r.id.state ); //holder.profile_pic.setimageresource( row_pos.getprofile_pic_id() ); holder.ednum = ( edittext ) convertview.findviewbyid( r.id.ednum ); holder.plus = ( imagebutton ) convertview.findviewbyid( r.id.plus ); holder.minus = ( imagebutton ) convertview.findviewbyid( r.id.minus ); convertview.settag( holder ); } else { holder = ( viewholder ) convertview.gettag(); } row_pos = rowitems.get( position ); bitmap bitmap = decodesampledbitmapfrompath( filepath + row_pos.getstatus() + filepath1 , 400 , 225 ); holder.profile_pic.setimagebitmap( bitmap ); //holder.profile_pic.setimageresource( row_pos.getprofile_pic_id() ); holder.member_name.settext( row_pos.getmember_name() ); holder.plus.setfocusable( false ); holder.minus.setfocusable( false ); holder.plus.settag( position ); holder.minus.settag( position ); holder.ednum.settag( position ); holder.plus.setonclicklistener( new view.onclicklistener() { @override public void onclick( view v ) { string tag = v.gettag().tostring(); if ( tag != null ) { pos = integer.parseint( tag ); selectedrowitem = rowitems.get( pos ); } //initialvalues = selectedrowitem.getinitialvalues(); string initialvalues = selectedrowitem.getinitialvalues(); int finalinitialvalues = integer.parseint( initialvalues ); if ( finalinitialvalues >= min_range && finalinitialvalues <= max_range ) finalinitialvalues++; else finalinitialvalues = 0; selectedrowitem.setinitialvalues( finalinitialvalues + "" ); if ( finalinitialvalues > max_range ) finalinitialvalues = min_range; //holder.ednum.settext( row_pos.getmember_name() ); holder.ednum.settext( " " + finalinitialvalues ); } } ); holder.minus.setonclicklistener( new view.onclicklistener() { @override public void onclick( view v ) { string tag = v.gettag().tostring(); if ( tag != null ) { pos = integer.parseint( tag ); selectedrowitem = rowitems.get( pos ); } //initialvalues = selectedrowitem.getinitialvalues(); string initialvalues = selectedrowitem.getinitialvalues(); int finalinitialvalues = integer.parseint( initialvalues ); if ( finalinitialvalues >= min_range && finalinitialvalues <= max_range ) finalinitialvalues--; else { finalinitialvalues = 9; } selectedrowitem.setinitialvalues( finalinitialvalues + "" ); if ( finalinitialvalues < min_range ) finalinitialvalues = max_range; holder.ednum.settext( " " + finalinitialvalues ); } } ); homecoming convertview; } private imageview findviewbyid( int profilepic ) { // todo auto-generated method stub homecoming null; } protected void finish() { // todo auto-generated method stub } public static bitmap decodesampledbitmapfrompath( string path , int reqwidth , int reqheight ) { final bitmapfactory.options options = new bitmapfactory.options(); options.injustdecodebounds = true; bitmapfactory.decodefile( path , options ); options.insamplesize = calculateinsamplesize( options , reqwidth , reqheight ); // decode bitmap insamplesize set options.injustdecodebounds = false; bitmap bmp = bitmapfactory.decodefile( path , options ); homecoming bmp; } public static int calculateinsamplesize( bitmapfactory.options options , int reqwidth , int reqheight ) { final int height = options.outheight; final int width = options.outwidth; int insamplesize = 1; if ( height > reqheight || width > reqwidth ) { if ( width > height ) { insamplesize = math.round( ( float ) height / ( float ) reqheight ); } else { insamplesize = math.round( ( float ) width / ( float ) reqwidth ); } } homecoming insamplesize; } }
the problem seems in getview() method.
if ( convertview == null ) { convertview = minflater.inflate( r.layout.list_item , null ); holder = new viewholder(); // here should initialise(findviewbyid) views // remember don't set values textview/imageviews here convertview.settag( holder ); } else { holder = ( viewholder ) convertview.gettag(); } // here should set value of textviews , imageviews , clicklisteners
java android
Comments
Post a Comment