android - How to call onItemSelected programaticly? -


after made call of notifydatasetchanged, references onitemselected outofdate.

e.g

gallery.setonitemselectedlistener(new onitemselectedlistener() {             @override             public void onitemselected(adapterview<?> parent, view view,                     int position, long id) {                 onfront1 = (imageview) view;              }              @override             public void onnothingselected(adapterview<?> arg0) {                 // todo auto-generated method stub              }         }); 

getview

public view getview(final int position, view convertview,                 viewgroup parent) {               imview = new imageview(this.mycontext);              imview.setlayoutparams(new gallery.layoutparams(                     layoutparams.fill_parent, layoutparams.fill_parent));             imview.setontouchlistener(new ontouchlistener() {                    public boolean ontouch(view v, motionevent event) {                      imageview view = (imageview) v;                       onfront2 = view;                     return true; // indicate event handled                 }                });             onfront3 = imview;             return imview;         } 

rotate

public void rotates(view v) {         imageview iv = onfront;         bitmap b = ((bitmapdrawable) iv.getdrawable()).getbitmap();         matrix matrix = new matrix();         matrix.postrotate(geg);         bitmap bmaprotate = bitmap.createbitmap(b, 0, 0, b.getwidth(),                 b.getheight(), matrix, true);         iv.setimagebitmap(bmaprotate);         geg = 90;         log.d("rorate", "yes");      } 

onfront references old imageview, cannot use more. how can call onitemselected again?

a bit more detailed:

i taking imageview , use in rotates function. uses onfront replace global variables onfront1|onfront2|onfront3
onfron1 allows rotate image appears on screen, became useless after notifydatasetchanged.
onfront2 not affected notifydatasetchanged, works after screen taped ( prety logical)
onfront3 not work @ all.
want achieve - hold reference current imageview , update imageview updated.

it better reassign onfront @ same code block, call notifydatasetchanged.

if somehow cannot in scenario, need additional mechanism track payload inside listadapter.

for example, want mark selected items specific color. can introduce itemdata class:

public class itemdata{     public bool isselected;     // other data if need, maybe link image view } 

you listadapter should use list of these objects (listdata) , implement getitem() method:

public object getitem(int i) {     return this.listdata.get(i); } 

when select item - in listener call

((itemdata)parent.getitem(position)).isselected = true; 

then, if add new item above selected, should add new item inside listdata. position of selected item change, associated itemdata instance not.


Comments

Popular posts from this blog

c++ - End of file on pipe magic during open -

basic authentication with http post params android -

data.table making a copy of table in R -