2009年5月27日水曜日

Android で数独 - onClick -

新しい Activity を定義して起動する。

レイアウトを設定
Sudoku/res/layout/about.xml



xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
>
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_text"
/>



More...

Sudoku/res/values/strings.xml




Sudoku
Android Sudoku
Continue
New Game
About
About Android Sudoku
\
Sudoku is a logic-based number placement puzzle.
Starting with a partially completed 9x9 grid, the
objective is to fill the grid so that each row,
each column, and each of the 3x3 boxes
(also called blocks) contains the digits
1 to 9 exactly once.

Exit



Sudoku/src/org/example/sudoku/About.java


package org.example.sudoku;

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

public class About extends Activity{
@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.about);
}
}


Sudoku/src/org/example/sudoku/Sudoku.java


package org.example.sudoku;

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

public class Sudoku extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

View continueButton = this.findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = this.findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = this.findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = this.findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}

public void onClick(View v) {
switch(v.getId()){
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
}
}

}


Sudoku/AndroidManifest.xml



xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.sudoku"
android:versionCode="1"
android:versionName="1.0">
android:icon="@drawable/icon"
android:label="@string/app_name">
android:name=".Sudoku"
android:label="@string/app_name">





android:name=".About"
android:label="@string/about_title">






About ボタンをクリックするとこんな感じ



0 件のコメント:

コメントを投稿