Here is my code: it contains a button named as button1A and when I click on it, It opens a list named as list1. How can I put a code for my another button named as button2A which open a list as List2.
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Tab_1st extends Activity {
Button button1A;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tablayout1);
addListenerOnButton();
}
public void addListenerOnButton() {
button1A = (Button) findViewById(R.id.button1A);
button1A.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent a1 = new Intent(v.getContext(), List1.class);
startActivity(a1);
}
});
}
}
you can add more click listeners if you want. try like this.
}
One way of doing this can be by implementing the OnClickListener.
Change your
addListenerOnButton
method usingswitch-case
to minimize code and add singleOnClickListener
listener to multiple button as :