アプリは正常に起動しますが、Select_Players ボタンをクリックしても、デバイスにダイアログ ボックスが表示されません。コードは次のとおりです。
public class MainActivity extends Activity {
private Button selectPlayers;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
super.onStart(); //customize
super.onResume(); //customize
selectPlayers = (Button) findViewById(R.id.add_players);
selectPlayers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launch dialogbox on click
onCreateDialog(savedInstanceState);
}
});
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
@SuppressWarnings("rawtypes")
final ArrayList mSelectedItems = new ArrayList(); // Where we track the selected items
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Set the dialog title
builder.setTitle(R.string.select_players)
// Specify the list array, the items to be selected by default (null for none),
// and the listener through which to receive callbacks when items are selected
.setMultiChoiceItems(R.array.players_name, null,
new DialogInterface.OnMultiChoiceClickListener() {
@SuppressWarnings("unchecked")
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the selected items
mSelectedItems.add(which);
} else if (mSelectedItems.contains(which)) {
// Else, if the item is already in the array, remove it
mSelectedItems.remove(Integer.valueOf(which));
}
}
})
// Set the action buttons
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//CODE TO CLOSE DIALOGBOX AND START FORGE
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//CODE TO JUST CLOSE DIALOGBOX
}
});
return builder.create();
}
}
Dialog メソッドが Dialog を返すようですが、onClick の結果としてそれを表示する方法がわかりません。(参考までに、Dialog メソッドは Android dev. Web サイトから取得しました。)
ありがとうございました!