android - How to get the id resource id of a view in a List view -


i have listview showing different images of animals,birds,reptiles. list view working fine. want when user click picture should appear in imageview.the imageview below listview. when ever user click image in listview should appear in imageview.

also there button. want achieve when user select image , press ok button paticular image should show on image view of other activity also. know can send id through intent.putextra(), problem first place how id of particular picture.

source code

public class mainactivity2 extends actionbaractivity {  private typedarray listicons; private horizontallistview listview; private arraylist<animalslistitems> suititems; private  animalslistadapter adapter1 = null;  /** array of strings populate dropdown list */ string[] actions = new string[] {         "bookmark",         "subscribe",         "share" }; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main_activity2);     listview = (horizontallistview) findviewbyid(r.id.suits_list);     animalsitems = new arraylist<animalslistitems>();     /** create array adapter populate dropdownlist */     arrayadapter<string> adapter = new arrayadapter<string>(getbasecontext(), android.r.layout.simple_spinner_dropdown_item, actions);       /** enabling dropdown list navigation action bar */     getsupportactionbar().setnavigationmode(actionbar.navigation_mode_list);     getsupportactionbar().setdisplayshowtitleenabled(false)     ;     getsupportactionbar().setdefaultdisplayhomeasupenabled(true);     getsupportactionbar().settitle("    "+"            "+"     ");      /** defining navigation listener */     android.support.v7.app.actionbar.onnavigationlistener navigationlistener = new android.support.v7.app.actionbar.onnavigationlistener() {          @override         public boolean onnavigationitemselected(int itemposition, long itemid) {             toast.maketext(getbasecontext(), "you selected : " + actions[itemposition], toast.length_short).show();                listicons = getresources()                     .obtaintypedarray(r.array.ic_launcher);// load icons             // strings.xml             (int = 0; i<=listicons.length(); i++) {                  animalsitems.add(new animalslistitems(listicons.getresourceid(i,-1)));             }             adapter1 = new suitslistadapter(getapplicationcontext(),suititems);             log.v(adapter1.getcount()+"");             listview.setadapter(adapter1);              return false;         }     };      listview.setonitemclicklistener(new adapterview.onitemclicklistener() {              @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {     //with position parameter, can fetch item @ clicked position below. cast whatever type listview is.      object youritem = (object) listview.getitematposition(position);          //now can assign image imageview                       }            });              /** setting dropdown items , item navigation listener actionbar */             getsupportactionbar().setlistnavigationcallbacks(adapter, navigationlistener);      this.overridependingtransition(r.anim.anim_slide_in_left,             r.anim.anim_slide_out_left); } 

}

for listview, can set onitemclicklistener below

listview listview1 = (listview) findviewbyid(r.id.listview1); listview1.setonitemclicklistener(new onitemclicklistener() {     @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {         //with position parameter, can fetch item @ clicked position below.          animalslistitems youritem = (animalslistitems) listview1.getitematposition(position);         //now can assign image imageview      } } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -