Here's the code for the main activity:
package com.example.gameproject;
import android.os.Bundle;
import android.app.Activity;
import android.app.SearchManager.OnCancelListener;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;
public class MainMenu extends Activity implements onclickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
Button startGame = (Button)findViewById(R.id.startGame);
startGame.setonclickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main_menu, menu);
return true;
}
void startGame(View v){
Intent startGame = new Intent(this, StartGameActivity.class);
startActivity(startGame);
}
@Override
public void onclick(View v) {
// TODO Auto-generated method stub
}
}
Here's the layout xml for that activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainMenu" >
<Button
android:id="@+id/startGame"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="82dp"
android:onclick="startGame"
android:text="@string/startGame" />
<Button
android:id="@+id/exit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/highScores"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="Exit" />
<Button
android:id="@+id/highScores"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/startGame"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:onclick="startScores"
android:text="@string/highScores" />
</RelativeLayout>
here's the start game activity:
package com.example.gameproject;
import android.app.Activity;
import android.os.Bundle;
public class StartGameActivity extends Activity {
Draw view;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(view);
}
}
here's my draw class that provides that startGameActivity view:
package com.example.gameproject;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class Draw extends View {
Paint paint;
public Draw(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
paint.setColor(Color.BLACK);
canvas.drawColor(Color.CYAN);
//canvas.drawText("5.5", canvas.getWidth()/2, canvas.getHeight()/2, paint);
}
}
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gameproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.gameproject.MainMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartGameActivity"
android:label="This is the name of your game"
/>
</application>
</manifest>
And finally, the logcat:
12-29 18:33:27.785: V/InputMethodManager(13441): Has been inactive! Starting fresh 12-29 18:33:27.785: V/InputMethodManager(13441): Starting input: tba=android.view.inputmethod.EditorInfo@41528a78 ic=null
Not much to the logcat

New Topic/Question
Reply


MultiQuote





|