How to access Array on Position in android -
i have grid view imageview , textview , show albums every singer when press on name album open new activity listview show every songes singer specific need knowledge how ? create gridview wit imageview , textview don't know rest please code imageadapter.java
public class imageadapter extends baseadapter { private context mcontext; string [] namelistreads; int[] imageid ; int []linkses; string [] namesora; private static layoutinflater inflater = null; //constructor public imageadapter(context context,string[] namelistread, int [] nameimages, int links[], string namesora[]){ this.namelistreads = namelistread; this.mcontext = context; this.imageid = nameimages; this.linkses = links; this.namesora = namesora; inflater = (layoutinflater)mcontext.getsystemservice(mcontext.layout_inflater_service); } @override public int getcount() { return namelistreads.length; } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } //create new imageview each item referenced adapter @override public view getview(final int position, final view convertview, viewgroup parent) { holder holder = new holder(); view rowview; rowview = inflater.inflate(r.layout.custom_name_reader,null); holder.tv = (textview) rowview.findviewbyid(r.id.textviewshow); holder.img = (imageview) rowview.findviewbyid(r.id.imageview); holder.tv.settext(namelistreads[position]); holder.img.setimageresource(imageid[position]); rowview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // toast.maketext(mcontext,"you clicked " + namelistreads[position] +"\n"+imageid[position],toast.length_long).show(); //send intent singleviewactivity // intent = new intent(mcontext,testshowfullimage.class); // i.putextra("id",position); // mcontext.startactivity(i); //__________________ intent = new intent(mcontext,listsoundreader.class); i.putextra("id",position); i.putextra("name",namesora[position]); mcontext.startactivity(i); } }); return rowview; } public class holder{ textview tv; imageview img; } }
fragmentgridview.java
public class fragmentgridview extends fragment { private gridview gridviewimage; // arraylist<parts> parts = new arraylist<>(); imageadapter imageadapter; public static string [] namereaderlist = {"محمدصديق المنشاوي","عبدالباسط عبدالصمد","الحصري","ماهر المعيقلي","المغامسي"}; //keep images in array public static int[] mthumbids = {r.drawable.elmenshawy, r.drawable.abdelbaset, r.drawable.alhosary, r.drawable.almaqely, r.drawable.almgamsy }; public static int [] links ={r.array.linkes, r.array.linkeselmenshawy, r.array.linkeselmenshawy, r.array.linkeselmenshawy, r.array.linkeselmenshawy}; public static string [] namesora = {string.valueof(r.array.name_allswar), string.valueof(r.array.name_allswar), string.valueof(r.array.name_allswar), string.valueof(r.array.name_allswar) , string.valueof(r.array.name_allswar)}; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment // return inflater.inflate(r.layout.fragment_list_parts, container, false); view rootview = inflater.inflate(r.layout.fragment_grid_view, null); getallwidgets(rootview); setadapter(); return rootview; } private void getallwidgets(view view) { gridviewimage = (gridview) view.findviewbyid(r.id.gridview); } private void setadapter() { imageadapter = new imageadapter(getactivity(),namereaderlist,mthumbids,links,namesora); gridviewimage.setadapter(imageadapter); } } listsoundreader.java public class listsoundreader extends appcompatactivity{ private recyclerview recycleviewsound; arraylist<parts> dataarraylist = new arraylist<>(); recycleviewadaptor recycleviewadaptor; @override protected void oncreate(@nullable bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_list_sound); intent ii = getintent(); int position = ii.getextras().getint("id"); recycleviewsound = (recyclerview)findviewbyid(r.id.recycleviewsound); //fetch data in string.xml file // string []arraykoran=getresources().getstringarray(r.array.name_allswar); string arraykoran=fragmentgridview.namesora[position]; string []arraylink=getresources().getstringarray(r.array.linkes); // string []arraylink=getintent().getextras().getstringarray(string.valueof(fragmentgridview.links)); dataarraylist.clear(); (int = 0; < arraykoran.length(); i++) { parts data = new parts(arraylink[i], arraylink[i]); dataarraylist.add(data); } recycleviewsound.setlayoutmanager(new linearlayoutmanager(getapplicationcontext())); recycleviewadaptor = new recycleviewadaptor(getapplicationcontext(), dataarraylist); recycleviewsound.setadapter(recycleviewadaptor); } public class listsoundreader extends appcompatactivity{ private recyclerview recycleviewsound; arraylist<parts> dataarraylist = new arraylist<>(); recycleviewadaptor recycleviewadaptor; @override protected void oncreate(@nullable bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_list_sound); intent ii = getintent(); int position = ii.getextras().getint("id"); recycleviewsound = (recyclerview)findviewbyid(r.id.recycleviewsound); //fetch data in string.xml file // string []arraykoran=getresources().getstringarray(r.array.name_allswar); string arraykoran=fragmentgridview.namesora[position]; string []arraylink=getresources().getstringarray(r.array.linkes); // string []arraylink=getintent().getextras().getstringarray(string.valueof(fragmentgridview.links)); dataarraylist.clear(); (int = 0; < arraykoran.length(); i++) { parts data = new parts(arraylink[i], arraylink[i]); dataarraylist.add(data); } recycleviewsound.setlayoutmanager(new linearlayoutmanager(getapplicationcontext())); recycleviewadaptor = new recycleviewadaptor(getapplicationcontext(), dataarraylist); recycleviewsound.setadapter(recycleviewadaptor); } } } how query links every singer on 1 hand ؟
steps achieve this
- create recyclerview
- create custom adapter recyclerview
- implement onclicklistener viewholder class link
- in override onclick method open new activity , show data.( if want click listener in activity or fragment create interface set value in adapter , click listener in activity.
wiki
Comments
Post a Comment