Android : setting event listener(onClickListener) for a button in android app development

on Friday, April 17, 2015



Why do we create an event listener such as onClickListener for a button in the following way:-


...
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mTrueButton = (Button)findViewById(R.id.true_button);

mTrueButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// Does nothing yet, but soon!
} });}


Why is mTrueButton using setOnClickListener method and not OnClickListener. Why this approach?


0 comments:

Post a Comment