Reputation: 798
I am trying to make a toolbar with a few buttons on it in a custom linearlayout class called "ToolBarLayout".
When i instance this i want to be able to add a custom listener to it so i can switch which button index was pressed in the main activity. Unfortunately i do not know how to pass the button's click events to the parent.
I have tried adding onclick to the toolbar in the hope that the view returned will be the actual view ID clicked, but it is always the parent.
Or perhaps there is another way? Anyone know of any examples like this?
Upvotes: 0
Views: 562
Reputation: 4187
Inflate the layout.After that, using findViewById(..) you can instantiate each button in separete view and add onClickListener().
P.S.
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View parentView = mInflater.inflate(R.layout.your_layout, parent, false);
Button btn = (Button)parentView.findViewById(R.id.button);
btn.setOnClickListener(...);
Something like that ... :)
Upvotes: 1