I’ve got an Activity which displays a list of custom components (in a LinearLayout). Each component represents a user in the database, and contains a button (among other things). When I click the button in the custom component, I want to pass a message back to the Activity to save the the user. The button knows the id of the user.
I was wondering how best to communicate back to the activity? In the click event of the button, should dispatch a new event (and catch it in the activity)? If so, can I add the user ID into the event? I’m new to events but I think I need to create my own custom event type perhaps?
The other way I thought of was to pass a reference for the activity into the component, so that the button can just call the method on the activity e.g ‘component.parentActivity=this’ but although I think it would work, I’m not sure if it’s the ‘proper’ way to do it.
Thanks
You can implement the View.OnClickListener interface. The onClick method you’ll need to implement will have the View (the thing that was clicked) passed to it. So you should have all the details about what was clicked and thus handle it the way you want from there.
What I’m not clear on in your question is what you mean by ‘component’? Is that a custom View? Or a layout of Views? Or other?