它是一個遊戲,在最後的活動中顯示分數但在此之前,輸入警報框顯示在用戶需要添加其名稱的位置,並且該名稱和分數應該到達數據庫。分數正在被儲存,但不是名稱。如何從輸入警報對話框中獲取名稱並將其設置爲db.insertScore(Score,Name)。我是如何將警報對話框的輸入值添加到extra.getString(「」);有吸氣&二傳手method.here是我的代碼從輸入警報對話框插入數據到數據庫
Bundle extra = getIntent().getExtras();
if (extra != null)
{
showInputDialog();
final String Name=extra.getString("");
final int Score = extra.getInt("SCORE");
final int totalQuestion = extra.getInt("TOTAL");
int correctAnswer = extra.getInt("CORRECT");
txtTotalScore.setText(String.format("SCORE : %d", Score));
txtTotalQuestion.setText(String.format("PASSED : %d/%d", correctAnswer, totalQuestion));
progressBarResult.setMax(totalQuestion);
progressBarResult.setProgress(correctAnswer);
db.insertScore(Score, Name);
}
}
protected void showInputDialog() {
// get prompts.xml view
LayoutInflater layoutInflater = LayoutInflater.from(Done.this);
View promptView = layoutInflater.inflate(R.layout.dialog, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Done.this);
alertDialogBuilder.setView(promptView);
final EditText editText = (EditText) promptView.findViewById(R.id.edittext);
// setup a dialog window
alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String Name = editText.getText().toString();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
你想說什麼? –