Android 在同一活动中显示Alertdialog
我有Android 在同一活动中显示Alertdialog,android,Android,我有警报对话框,但我想在同一活动中显示。我应该在下面的代码中添加什么 new AlertDialog.Builder(ContactAlertDialogActivity.this) .setTitle("Permission Required") .setMessage(("To set a contact ringtone,Old Telephone Ringtones needs access to your contacts
警报对话框
,但我想在同一活动中显示。我应该在下面的代码中添加什么
new AlertDialog.Builder(ContactAlertDialogActivity.this)
.setTitle("Permission Required")
.setMessage(("To set a contact ringtone,Old Telephone Ringtones needs access to your contacts.We never read " +
(",store or share your contact information in any way." +
"On the next screen tap Allow")))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton("NOT NOW", null)
.setIcon(R.drawable.phone)
.show();
尝试在“活动”中的任意位置创建对话框的方法,并在要显示警报对话框的每个位置调用它
private void DisplayAlertDialogBox(string _title, string _body)
{
AlertDialog alertDialog = new AlertDialog.Builder(this)
//set icon
.setIcon(android.R.drawable.ic__alert)
//set title
.setTitle(_title)
//set message
.setMessage(_body)
//set positive button
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//set what would happen when positive button is clicked
finish();
}
})
//set negative button
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//set what should happen when negative button is clicked
Toast.makeText(getApplicationContext(),"Nothing Happened",Toast.LENGTH_LONG).show();
}
}).show();
}
现在有什么问题。。它应该在
ContactAlertDialogActivity
活动中打开,您正在将其上下文传递给它,但它在RecyclerView中。我该怎么办?