public class MainActivity extends AppCompatActivity {
private Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.q);
b.setOnClickListener(movetonext(););
}
public void movetonext()
{
Intent intent=new Intent(MainActivity.this,go.class);
startActivity(intent);
}
}
Asked
Active
Viewed 67 times
-4
-
Dear VISH Welcome to SO. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – Ali Mar 12 '20 at 07:40
-
Refer this: https://stackoverflow.com/questions/13194081/how-to-open-a-second-activity-on-click-of-button-in-android-app – Ali Mar 12 '20 at 07:41
-
b.setOnClickListener(movetonext();); This is not even how Android works. Please see how onClickListener is implemented in Android – Shubham Goel Mar 12 '20 at 07:47
-
Does this answer your question? [How to open a second activity on click of button in android app](https://stackoverflow.com/questions/13194081/how-to-open-a-second-activity-on-click-of-button-in-android-app) – Satan Pandeya Mar 12 '20 at 08:03
1 Answers
1
Change your click listener like below -
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
movetonext();
}
});
Hope this will help you.

Dipankar Baghel
- 1,932
- 2
- 12
- 24