gpt4 book ai didi

android - 在 Android 上的 onPrepareDialog 上自定义 AlertDialog 的内容时透明背景和无按钮

转载 作者:搜寻专家 更新时间:2023-11-01 09:12:30 24 4
gpt4 key购买 nike

我在使用 onPrepareDialog 方法更新 AlertDialog 的内容时遇到了一些困难。

我正在设置 AlertDialog 的内容,但是出现在屏幕上的对话框没有按钮也没有背景。问题可能与 Builder 有关。

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_USER_INFORMATION:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
return builder.create();
default:
return null;
}
}

@Override
protected void onPrepareDialog(final int id, final Dialog dialog) {
switch (id) {
case DIALOG_USER_INFORMATION:
createUserInformationAlertDialog(dialog);
break;
}
}

public void createUserInformationAlertDialog(Dialog dialogIn) {
AlertDialog alertDialog = (AlertDialog) dialogIn;
View dialoglayout = alertDialog.getLayoutInflater().inflate(
R.layout.dialog_user_info,
(ViewGroup) findViewById(R.id.dialog_user_layout_root));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
EventAttendant ea = this.event.getCrowd().getAttendees()
.get(positionUserToHaveInformationDisplayedOnTheDialog);
final EventAttendant clone = (EventAttendant) ea.clone();

// Setting values
TextView textView = (TextView) dialoglayout.findViewById(R.id.user_name_value);
textView.setText(ea.getName());

builder.setPositiveButton(Locale_PT_BR.SEE_ON_FACEBOOK,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {/* User clicked OK so do some stuff */
}
});
builder.setNegativeButton(Locale_PT_BR.BACK,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {...}
});
builder.setView(dialoglayout);
alertDialog.setView(dialoglayout);
alertDialog.setContentView(dialoglayout);
}

最佳答案

您应该在 onCreateDialog() 中创建对话框并在 onPrepareDialog() 中更改文本。

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_USER_INFORMATION:
return createUserInformationAlertDialog();

default:
return null;
}
}

@Override
protected void onPrepareDialog(final int id, final Dialog dialog) {
switch (id) {
case DIALOG_USER_INFORMATION:
prepareUserInformationAlertDialog((AlertDialog)dialog)
break;
}
}

public Dialog createUserInformationAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton(Locale_PT_BR.SEE_ON_FACEBOOK,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {/* User clicked OK so do some stuff */
}
});
builder.setNegativeButton(Locale_PT_BR.BACK,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {...}
});
return builder.create();
}

public void prepareUserInformationAlertDialog(AlertDialog alertDialog) {
EventAttendant ea = this.event.getCrowd().getAttendees()
.get(positionUserToHaveInformationDisplayedOnTheDialog);
final EventAttendant clone = (EventAttendant) ea.clone();

View dialoglayout = alertDialog.getLayoutInflater().inflate(
R.layout.dialog_user_info, null, false);
// Setting values
TextView textView = (TextView) dialoglayout.findViewById(R.id.user_name_value);
textView.setText(ea.getName());
alertDialog.setView(dialogLayout)
}

我没有测试过这段代码,所以它可能包含一些错误。

关于android - 在 Android 上的 onPrepareDialog 上自定义 AlertDialog 的内容时透明背景和无按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7275259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com