This is my code in my main java file. How would i make another button to connect with the activity. please tell me if i am not expressing this well enough. I just need to add another button into the main java file. I already have an activity in the manifest and a class for it, i just need to put another block of code into the main java file. The id of the button is p40, the name of the xml layout is p40.xml, the class is called p40.java and the activity is called p40. This is my code at the moment:
package com.duncan.hello.world;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.duncan.hello.world.R;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Button aButton;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aButton = (Button) this.findViewById(R.id.button1);
aButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(HelloWorldActivity.this, OtherActivity.class);
startActivity(i);
}});
}
}
You should do
You have to add another
button1inlayout/main.xmlfile.