Hi all,
I have just started on my first app. I was just wondering how can I move from one activity to another.
I have used onClickListeners. It does not seem to work for me even though I have pretty much followed every tutorial I can find step by step.
mainmenu.java
main.xml
Any advise would be much appreciated!!
I have just started on my first app. I was just wondering how can I move from one activity to another.
I have used onClickListeners. It does not seem to work for me even though I have pretty much followed every tutorial I can find step by step.
mainmenu.java
Code:
package com.transport.assistant;
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;
public class mainmenu extends Activity {
/** Called when activity is initially created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// click-handlers for buttons
Button underground = (Button) findViewById(R.id.ButtonM1);
underground.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(view.getContext(), underground.class);
startActivityForResult(myIntent, 0);
}
});
}
}
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/app_name">
</TextView>
<Button
android:id="@+id/ButtonM1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Underground">
</Button>
<Button
android:id="@+id/ButtonM2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Bus">
</Button>
<Button
android:id="@+id/ButtonM3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/oyster_locations">
</Button>
<Button android:id="@+id/ButtonM4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/plan_journey">
</Button>
<Button
android:id="@+id/ButtonM5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Settings">
</Button>
</LinearLayout>
Any advise would be much appreciated!!