Tuesday, 15 July 2014

java - How to implement OnSetClickListener for button in RecyclerView? -


I am having difficulty in clicking on my device register button inside the Android recycling and I'm not sure why I do not answer I am looking around and it seems that this should work but I really want to know whether I have put things in the wrong place, am I forgetting something and if so what?

Holder Class

  Public class viewer expanded RecyclerView.ViewHolder {public TextView time; Public image button; Public viewer (see V) {super (V)}; Time = (text view) v.findViewById (RID.time); Button = (image button) v.findViewById (R.id.imageButton); Click Button.setOnClickListener (New View.OnClickListener) {@Override Public Zero (see V) {Log D. ("Test", "Button Click");}}); }}  

Adapter class

  Public class ListAdapter RecyclerView.Adapter and lt; ViewHolder & gt; {// timer object passed through aelliist; Timer & gt; LData = null; // Provide a suitable constructor (depending on the type of dataset) Public ListAdapter (ArrayList & gt; timer & gt; myDataset) {lData = myDataset; } @ Override public viewer inventory holder (see group origin, int view type) {see v = layoutInflator. From (parent.getContext ()) .inflate (R.layout.list_adapter, parent, false); ViewHolder vh = new viewer (v); Return VH; } // Change the contents of a scene (applied by Layout Manager) @ Override Public Zero Adjustment Viewholder (seeholder holder, int status) {holder.time.setText (lData.get (.get) .getTime ()); } // Return the size of your dataset (brought by layout manager) @ override public int iacomaccount () {return ldita. size (); } // timer public aliist & lt; Timer & gt; GetData () {Return lData; }}  

main activity orbit (onset method)

  @ override protected zero creation (bundle saved instanestate) {super.naught (savedinstenstate ); SetContentView (R.layout.activity_main); MRecyclerView = (Recycler Vij) Search ViewById (R.id.recycler_view); MRecyclerView.setHasFixedSize (true); MLayoutManager = New LinearLayoutManager (this); MRecyclerView.setLayoutManager (mLayoutManager); MAdapter = new list adapter (timer); MRecyclerView.setAdapter (mAdapter); }  

View items

  & lt; Relative layout xmlns: android = "http://schemas.android.com/apk/res/android" Android: Layout_width = "fill_parent" Android: layout_height = "? Android: Attribute / ListItim Hight" Android: Padding = "6 DP" Android: Layout_margin = "6 DP" Android: Background = "Android: Syllable Eatam Background" & gt; & Lt; Android: layout_heid = "wrap_content" Android: gravity = "fill_vertical" Android: textSize = "28sp" Android: text = "00:00: 00" "Android: paddingLeft =" 10dip "Android: layout_centerVertical =" true "Android: layout_toEndOf =" @ + id / imageButton "/> Android: layout_alignParentTop = "true" Android: layout_alignParentBottom = "true" Android: src = "@drawable / android: layout_held =" rap_content "android: ic_action_pause" /> & Lt; / RelativeLayout & gt;  


No comments:

Post a Comment