私は難易度レベルがダイアログボックスに表示されているゲームを作成していますが、難易度のダイアログボックスを表示する方法を理解できませんクリックされます。私はarray.xmlとstring.xmlの難易度レベルの私のコードを持っています。「新しいゲーム」ボタンをクリックすると、ダイアログが表示されます
arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="difficulty">
<item>@string/novice_label</item>
<item>@string/easy_label</item>
<item>@string/medium_label</item>
<item>@string/guru_label</item>
</array>
</resources>
のstrings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Brain Training Game</string>
<string name="main_title">Brain Training Game</string>
<string name="new_game_label">New Game</string>
<string name="continue_label">Continue</string>
<string name="about_label">About</string>
<string name="exit_label">Exit</string>
<string name="about_title">About Brain Training Game</string>
<string name="about_text">\
Brain Training Game 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="new_game_title">Difficulty</string>
<string name="novice_label">Novice</string>
<string name="easy_label">Easy</string>
<string name="medium_label">Medium</string>
<string name="guru_label">Guru</string>
</resources>
Btg.Java
package org.example.btg;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.os.Bundle;
public class BrainTrainingGame extends Activity implements OnClickListener {
protected static final String TAG = null;
/** Called when the activity is first created. */
@SuppressWarnings("null")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = 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.exit_button:
finish();
break;
case R.id.new_button:
openNewGameDialog();
break;
}
}
public void openNewGameDialog() {
new AlertDialog.Builder(this);
setTitle(R.string.new_game_title);
setItems(R.array.difficulty,new DialogInterface.OnClickListener()
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface, int i) {
startGame(i);
}
})
.show();
}
private void startGame(int i){
Log.d(TAG, "clicked on " +i);
}
}
事前に助けてくれてありがとう;)
ありがとうございました..それは働きました!!!!!!!!!!!!!!!!! !!! :D –