Monday, 15 February 2010

android - Different content for each Spinner item in the same Activity -



android - Different content for each Spinner item in the same Activity -

how can show different content after selecting item spinner? want create spinner locations of chain stores.

i want spinner there on top. thing changes content under spinner

create simple method in activity refresh layout below spinner(which remain untouched). method called onitemselectedlistener set on spinner. this:

private void changeadress(int newselectedadress) { // imageview , textview in layout imageview map = (imageview) findviewbyid(r.id.theidoftheimage); // set image. know current address selected user // (the newselectedaddress int) array/list/database // stored // set image }

called method above onitemselected callback:

yourspinnerrefference.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { changeaddress(position); } @override public void onnothingselected(adapterview<?> parent) { } });

if not want, please explain.

edit: create 2 arrays hold data:

int[] images = {r.drawable.imag1, r.drawable.imag2 ..etc...}; //also text string[] text = {"text1", "text2 ...etc...};

then utilize 2 arrays in method recommended above:

private void changeadress(int newselectedaddress) { ((imageview)findviewbyid(r.id.mapview1)).setimageresource(images[newselectedaddress]); // assing id textview in layout , same above. }

there no need multiple imageview , textviews.

android android-activity spinner

No comments:

Post a Comment