メッセージを出力するメソッドを持っている
・Log.e():エラー
・Log.w():警告
・Log.i():情報
・Log.d():デバッグ
・Log.v():冗長
Eclipse でこのログをみるには
[Window] -> [Show View] -> [Other...] -> [Android] -> [LogCat]
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
Settings...
Sudoku settings
s
Music
Play background music
Hints
Show hints during play
Difficulty
Easy
Medium
Hard
リストの形式を記述
Sudoku/res/values/arrays.xml
- @string/easy_label
- @string/medium_label
- @string/hard_label
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;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
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;
case R.id.new_button:
openNewGameDialog();
break;
case R.id.exit_button:
finish();
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.settings:
startActivity(new Intent(this, Settings.class));
return true;
}
return false;
}
private void openNewGameDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.new_game_title)
.setItems(R.array.difficulty,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface, int i) {
startGame(i);
}
})
.show();
}
private static final String TAG = "Sudoku";
private void startGame(int i) {
Log.d(TAG, "clicked on " + i);
// start game here
}
}
Exit ボタンを押したとき、Activity を破棄するために
finish()
を呼び出す
New Game をクリックすると難易度の選択ポップアップが表示される
0 件のコメント:
コメントを投稿