I\'m a beginner to android, while setting onclick listener to a button, what does the parameter passed mean:
btn1.setOnClickListener(new OnClickListener() {
To instantiate an object of an interface or an abstract class, you need to override all of its not implemented methods (abstract methods). You can override the abstract methods by either using anonymous class or defining a class that extends the abstract class/implements the interface and override the abstract methods. However, to make it clearer, you can do it like this:
OnClickListener l = new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
}
});
btn1.setOnClickListener(l);
and to use a separate class, you can do it like this:
btn1.setOnClickListener(new MyOwnListener());
// ...
public class MyOwnListener implements OnClickListener
{
// ...
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
}
}