Android Studio recycleview to detail not working -


i have problem in show detail class recycleview, recycleview show detail not function, not understand how make on click position in recycle view,

this listberita.java

                     stringrequest = new stringrequest(request.method.get, url, new response.listener<string>() {              @override              public void onresponse(string response) {                  log.d("response ", response);                  try {                      jsonobject jsonobject = new jsonobject(response);                      jsonarray jsonarray = jsonobject.getjsonarray("berita");                      (int = 0; < jsonarray.length(); a++) {                          jsonobject json = jsonarray.getjsonobject(a);                          hashmap<string, string> map = new hashmap<string, string>();                          map.put("id_berita", json.getstring("id_berita"));                          map.put("id_pos", json.getstring("id_pos"));                          map.put("nama_pos", json.getstring("nama_pos"));                          map.put("gambar_berita", json.getstring("gambar_berita"));                          map.put("berita", json.getstring("berita"));                          list_data.add(map);                          adapterlist adapter = new adapterlist(listberita.this, list_data);                          beritalist.setadapter(adapter);                          }                  } catch (jsonexception e) {                      e.printstacktrace();                  }                }        <!-- begin snippet: js hide: false console: true babel: false -->

            @override             public void onerrorresponse(volleyerror error) {                 toast.maketext(listberita.this, error.getmessage(), toast.length_short).show();             }         });          requestqueue.add(stringrequest);     }  } 

, adapter

package baru.azoel.ayomuncak.adapter;    import android.content.context;  import android.content.intent;  import android.support.v7.widget.recyclerview;  import android.view.layoutinflater;  import android.view.view;  import android.view.viewgroup;  import android.widget.imageview;  import android.widget.textview;    import com.bumptech.glide.glide;    import java.util.arraylist;  import java.util.hashmap;    import baru.azoel.ayomuncak.detailberita;  import baru.azoel.ayomuncak.listberita;  import baru.azoel.ayomuncak.r;    /**   * created azoel.   */  public class adapterlist extends recyclerview.adapter<adapterlist.viewholder>{        context context;      arraylist<hashmap<string, string>> list_data;        public adapterlist(listberita beritaactivity, arraylist<hashmap<string, string>> list_data) {          this.context = beritaactivity;          this.list_data = list_data;        }        @override      public viewholder oncreateviewholder(viewgroup parent, int viewtype) {          view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.list_item_berita, null);          return new viewholder(view);      }        @override      public void onbindviewholder(viewholder holder, int position) {          glide.with(context)                  .load("http://marimuncak.000webhostapp.com/images/" + list_data.get(position).get("gambar_berita"))                  .crossfade()                  .placeholder(r.mipmap.ic_launcher)                  .into(holder.imgberita);          holder.txtnama.settext(list_data.get(position).get("nama_pos"));          holder.txtberita.settext(list_data.get(position).get("berita"));                 }          @override      public int getitemcount() {          return list_data.size();      }        public class viewholder extends recyclerview.viewholder {          textview txtberita;          imageview imgberita;          textview txtnama;          public viewholder(view itemview) {              super(itemview);              txtnama = (textview) itemview.findviewbyid(r.id.txtnama);              txtberita = (textview) itemview.findviewbyid(r.id.txtberita);              imgberita = (imageview) itemview.findviewbyid(r.id.imgberita);          }      }    }

public class adapterlist extends recyclerview.adapter<adapterlist.viewholder>{  context context; arraylist<hashmap<string, string>> list_data;  public adapterlist(listberita beritaactivity, arraylist<hashmap<string, string>> list_data) {     this.context = beritaactivity;     this.list_data = list_data;  }  @override public viewholder oncreateviewholder(viewgroup parent, int viewtype) {     view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.list_item_berita, null);     return new viewholder(view); }  @override public void onbindviewholder(viewholder holder, int position) {     glide.with(context)             .load("http://marimuncak.000webhostapp.com/images/" + list_data.get(position).get("gambar_berita"))             .crossfade()             .placeholder(r.mipmap.ic_launcher)             .into(holder.imgberita);     holder.txtnama.settext(list_data.get(position).get("nama_pos"));     holder.txtberita.settext(list_data.get(position).get("berita"));    holder.itemview.setonclicklistener(new view.onclicklistener() {    @override    public void onclick(view v) {      onitemclicklistener.onitemclick(position);    } });  }   @override public int getitemcount() {     return list_data.size(); }  public class viewholder extends recyclerview.viewholder {     textview txtberita;     imageview imgberita;     textview txtnama;     public viewholder(view itemview) {         super(itemview);         txtnama = (textview) itemview.findviewbyid(r.id.txtnama);         txtberita = (textview) itemview.findviewbyid(r.id.txtberita);         imgberita = (imageview) itemview.findviewbyid(r.id.imgberita);     } }     public void setonitemclicklistener(onitemclicklistener onitemclicklistener){     this.onitemclicklistener = onitemclicklistener; }  onitemclicklistener onitemclicklistener;    public interface onitemclicklistener{     void onitemclick(int position); } } 

your activity. in oncreate()

 public class testactivity extends appcompatactivity implements adapterlist.onitemclicklistener {    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_test);      your_adapter.setonitemclicklistener(this); }    @override public void onitemclick(int position) {    // code here } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -