[英]Android AlertDialog not showing
我無法顯示警報對話框。 我將其置於調試模式,它貫穿了整個過程,然后即使調試器處理該行並繼續進行下一段代碼,也從不顯示菜單。
if(game.checkForPromotion(startRow, startCol)){
AlertDialog.Builder builder = new AlertDialog.Builder(GameActivity.this);
builder.setTitle("Pick a piece")
.setItems(R.array.pieces_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
builder.create().show();
Log.d("GameActivity: ", "Is it crashing before this?");
}
Log.d("GameActivity: ", "Totally done with alert");
// More Code
我使用您的源代碼運行,將[R.array.pieces_array]的值更改為我的變量[final CharSequence [] items = {“這是setItems的內容”};] 。 我運行程序,警報對話框顯示OK。 源代碼顯示對話框確定:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CharSequence[] items = {"This is content of setItems"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Pick a piece")
.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
builder.create().show();
Log.d("GameActivity: ", "Is it crashing before this?");
}
我認為您需要檢查文件中的其他源代碼。
試試這個,對我有用
new AlertDialog.Builder(getContext(), android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth)
.setTitle("Title")
.setMessage("My message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// get ok button click
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// get cancel button click
dialog.dismiss();
}
})
.show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.