• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps usng jave to link multiple activites from main screen

bumpn

Lurker
basically im trying to create 2 activities that will be navigation. I have the main page that has 7 buttons each button leads to a different page. I can get one button to work. Do I need to create 2 java files for each button? or can i just use the 2 and theres a way to combine them like im trying to do below.


activity1.java

package install.fineline;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class Activity1 extends Activity {

Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fineline);
addListenerOnButton();
}

public void addListenerOnButton() {

final Context context = this;

button = (Button) findViewById(R.id.autobody);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, Activity2.class);
startActivity(intent);

}

});

}




Button button1;

public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fineline);
addListenerOnButton();
}

public void addListenerOnButton1() {

final Context context = this;

button = (Button) findViewById(R.id.glass);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, Activity2.class);
startActivity(intent);

}

});

}

}


activity2.java

package install.fineline;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class Activity2 extends Activity {

Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autobody);
}



Button button1;

public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.glass);
}

}
 
Back
Top Bottom