android - 12 Buttons programmatically - How to handle each click -


I have created a custom linear layout view that generates 12 buttons, I would like to be able to handle each of those click events Here's my Qusum linear layout class:

  Public class Solution buttons liner layout (Private static id AMOUNT_BUTTONS = 6; Private static SIZE_BUTTONS = 130; Private static id PADDING = 13; Private Arrestist & lt; & Gt; Button; @TargetApi (Build.VERSION_CODES.HONEYCOMB) Public Solutions Buttons (Reference, attrs, defStyleAttr); in this ();} public solution buttons (reference references, attributeSet attrs) {super (references, attrs); in this ();} public Solution Button (Reference Reference); In this ();} Public Arrestist & lt; Button & gt; GetButtons () {Return Button;} Public Zero Init () {Button = New ArrayList & lt; Button & Gt; (); setOrientation (for vertical); (int i = 0; i & lt; 2; i ++) {liner layout lille = new linerlight (getContext ()); Ll.setOrientation (horizontal); For (int j = 0; j and lt; amOUNT_BUTTONS; J ++) {button b = new button (getContext ()); Layout Improved Layout Primers = New Layout Mercury (SIZE_BUTTONS, SIZE_BUTTONS); Layout Paramacet Margins (0, 0, padding, padding); B.setLayoutParams (layoutParams); B.setBackground (.getResources () getDrawable (R.drawable.solution_button_background)); Buttons.add (b); Ll.addView (b); } Edve (LL); }}}  

When I press, I want to be able to change the visibility of every button. I tried to apply it to OnClickListener - created a button in the for loop, but it did not work. any suggestion?

Then add a method to your class:

  Private onclick Leastner Onclick Listener = New Onclick Leastner () {@ Override Public Zero (click to see v) {switch (v.getId ()} {case R.D.Bat_Arm_date: break; Case R.id.but_arr_time: Break; Case R.id.but_update_arr: Break; Case R.id.but_fin_date: break; Case R.id.but_fin_time: Break; }}};  

and

for each button

  yourBut.setOnClickListener (onClickListener ). 

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -