Now you can Subscribe using RSS

Submit your Email


OnClickListener on custom list view's button

Vishal Shrestha
This post assumes you have knowledge of making custom lists using your own adapters.
If you are not sure how to do that, you can learn it here
Now what we need to do is to set onClickListener to a button inside the custom row of the list. Setting onLongClickListenter to the row is simple as we don't care about the elements inside the row, but if you want to set onClickListener to a button inside the row, you can do it the following way.

  • First refer to the button for which you want to set the listener in the getView() method of your Adapter.
  • Then Simply create the onClick() function outside the getView(), but inside the Adapter.
Here's a sample code from an app i was building-


public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
row = inflater.inflate(R.layout.customlistview, parent, false);
} else {
row = convertView;
favt = (ToggleButton) row.findViewById(;
TextView chapter = (TextView) row.findViewById(;
TextView content = (TextView) row.findViewById(;

return row;
public void onClick(View view) {
// TODO Auto-generated method stub
// Your onClick handling code here

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)


Research and Development at : Ekghanti

Mobile Technology Lead at : Vimvox Lab

For Business info : My Portfolio Site


Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha