As the title suggests, what is better technique to follow in Android? I referred few docs, but couldn't find much details that I need.
Consider I have 5+ views and I want to handle their clicks at one place, then creating a ClickListener object
and passing it is better or implementing the ClickListener interface
in the Activity/Fragment and then passing the instance of Activity/Fragment is better and why?
EDIT
Let me add an example since most of the people are unable to understand the statement
Case-1:
private final View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
//some code
}
};
public void doSomeTask(){
view1.setOnClickListener(onClickListener);
view2.setOnClickListener(onClickListener);
view3.setOnClickListener(onClickListener);
}
Case-2:
public class SomeActivity extends AppCompatActivity implements View.OnClickListener {
//some code
public void doSomeTask(){
view1.setOnClickListener(this);
view2.setOnClickListener(this);
view3.setOnClickListener(this);
}
@Override
public void onClick(View view) {
//some code
}
}
Which is the best approach Case-1 or Case-2 ?