For doing some Action on Button Click following these Steps :
STEP 1:
Add a button in your Activity layout as:
<Button
android:id="@+id/button_id_here"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
STEP 2:
Add your NextActivity
in AndroidManifest.xml
as:
<!-- your other xml -->
<application
<!-- your other xml -->
<activity
android:name=".NextActivity" />
</application>
STEP 3:
In MainActivity code add a Button click Listener to button_id_here as:
public class MainActivity extends Activity {
Button button_test; //<< Create Button instance here
Intent intent; //<< For starting new Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// Add layout to Activity here
setContentView(R.layout.your_Activity_layout);
// Initilie button here
button_test= (Button) findViewById(R.id.button_id_here);
// add a onclick listner to button here
button_test.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
intent = new Intent(MainActivity.this,NextActivity.class);
startActivity(intent); //<<< start Activity here
}
});
}
}
if still facing to do some activity on Button click then learn here:
solved How to use OnClick in android programming [closed]