メッセージを出力するメソッドを持っている
・Log.e():エラー
・Log.w():警告
・Log.i():情報
・Log.d():デバッグ
・Log.v():冗長
Eclipse でこのログをみるには
[Window] -> [Show View] -> [Other...] -> [Android] -> [LogCat]

More...
Sudoku/res/values/strings.xml
- <!--xml version="1.0" encoding="utf-8"?-->
- <resources>
- <string name="app_name">Sudoku</string>
- <string name="main_title">Android Sudoku</string>
- <string name="continue_label">Continue</string>
- <string name="new_game_label">New Game</string>
- <string name="about_label">About</string>
- <string name="about_title">About Android Sudoku</string>
- <string name="about_text">\
- 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 <i>blocks</i>) contains the digits
- 1 to 9 exactly once.
- </string>
- <string name="exit_label">Exit</string>
- <string name="settings_label">Settings...</string>
- <string name="settings_title">Sudoku settings</string>
- <string name="settings_shortcut">s</string>
- <string name="music_title">Music</string>
- <string name="music_summary">Play background music</string>
- <string name="hints_title">Hints</string>
- <string name="hints_summary">Show hints during play</string>
- <string name="new_game_title">Difficulty</string>
- <string name="easy_label">Easy</string>
- <string name="medium_label">Medium</string>
- <string name="hard_label">Hard</string>
- </resources>
リストの形式を記述
Sudoku/res/values/arrays.xml
- <!--xml version="1.0" encoding="utf-8"?-->
- <resources>
- <array name="difficulty">
- <item>@string/easy_label</item>
- <item>@string/medium_label</item>
- <item>@string/hard_label</item>
- </array>
- </resources>
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 件のコメント:
コメントを投稿