I have been doing some interesting work on android for the past few days, I am creating a “Take Away” application that can be used by Restaurants / Eating Houses to receive order from customer by their android phones.
Though I now know how to use most of the controls available in the Android SDK it was a little difficult for me to do some advance work with ListView control. I wanted to show a list of available dishes to the application users in a list view and the user could click on a button to add item to their order list and when they have added the item in their order list I wanted to show the quantity they need for each item and also an option to remove items from ordered list.
I have used the List View control in my earlier android development projects but did not do anything like this so I was confused on how to achieve this. I started thinking this as a complex thing to achieve so as always did some R&D on Google but found no direct solution.
I have used List/Repeater controls in asp.net development as well, so I had it on my mind that I will need to do some kind of event binding to child controls of each list item in the List View in my list adapter class but to my amazement the solution for this was far more simple.
The solution was just to write the method name on the android:onClick attribute of my image button controls and define the method in the Activity class, that is it! 🙂
The method receives the control View as parameter and you can perform the business logic in the method
Hope sharing this experience of my will save some time for someone 🙂