I would rather go for the click handling in code than using the onClick
attribute in XML when working with fragments.
This becomes even easier when migrating your activities to fragments. You can just call the click handler (previously set to android:onClick
in XML) directly from each case
block.
findViewById(R.id.button_login).setOnClickListener(clickListener);
...
OnClickListener clickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
switch(v.getId()) {
case R.id.button_login:
// Which is supposed to be called automatically in your
// activity, which has now changed to a fragment.
onLoginClick(v);
break;
case R.id.button_logout:
...
}
}
}
When it comes to handling clicks in fragments, this looks simpler to me than android:onClick
.