Reputation: 376
I created a new method to change activities because I don't want to repeat code.
Everytime that a textview is clicked, I call this method:
globalMethods.ChangeActivity(txtSignup,InitialActivity.this,RegistrationActivity.class);
Method code:
public static void ChangeActivity(TextView target, final Activity currentActivity, final Class<?> nextActivity){
target.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(currentActivity, nextActivity);
currentActivity.startActivity(intent);
currentActivity.overridePendingTransition(R.drawable.push_down_in,R.drawable.push_down_out);
}
});
}
Now I would like to adapt this code to every type of objects, like buttons.
Can you guys give me any suggestion of how can I check if the user clicked at a textview or a button, and send it to the parameter?
Thanks.
Upvotes: 0
Views: 35
Reputation: 16010
You can use this instead, as all widgets are inherit View
class:
public static void ChangeActivity(View target, final Activity currentActivity, final Class<?> nextActivity){
target.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(currentActivity, nextActivity);
currentActivity.startActivity(intent);
currentActivity.overridePendingTransition(R.drawable.push_down_in,R.drawable.push_down_out);
}
});
}
Upvotes: 1