onclick listener in android

sivaraj picture sivaraj · Aug 17, 2010 · Viewed 43.9k times · Source

I used two image button for Next and Back and i used onclick event for those button i want to which image button fire on onclick and run particular function for next or back in onclick event how will i get which image button fire or onclick event at runtime

Answer

Konstantin Burov picture Konstantin Burov · Aug 17, 2010

Use View.getId() to distinguish between different views that fire onClick events.

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.download:
    //code..
    break;
    case R.id.play:
    //code..
    break;
    case R.id.pause:
        //code..
    break;
    default:
        //code..
    break;
    }
}