我希望有人可以幫助我,我試圖顯示一個自定義對話框,但是當我點擊調用此方法的按鈕時,會出現灰色屏幕,就像顯示自定義對話框一樣,但要不顯示任何的XML。Android自定義對話框不工作
問題是,前幾天它的工作原理,但我沒有觸及什麼,現在它不起作用。 我試圖清理該項目並將其放回原位,然後移除應用程序並重新安裝。 測試應用程序以查看某些對象是否爲空,但顯示如果可用但不顯示xml。
JavaFile
private void NegativeAlertDialog()
{
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.my_alert_dialog, (ViewGroup) getCurrentFocus());
AlertDialog.Builder builderNegative = new AlertDialog.Builder(this);
builderNegative.setCancelable(false);
final AlertDialog alertNegative = builderNegative.create();
Button buttonSaturation = (Button)dialoglayout.findViewById(R.id.buttonSaturation);
buttonSaturation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertNegative.dismiss();
sendRefuseServiceOptionSaturation(Global.urlServer);
}
});
Button buttonNoZone = (Button)dialoglayout.findViewById(R.id.buttonNoZone);
buttonNoZone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertNegative.dismiss();
sendRefuseServiceOptionNotMyArea(Global.urlServer);
}
});
Button buttonLiquidity = (Button)dialoglayout.findViewById(R.id.buttonLiquidity);
buttonLiquidity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertNegative.dismiss();
sendRefuseServiceOptionLiquidityProblems(Global.urlServer);
}
});
Button buttonMyAlertDialogCancel = (Button)dialoglayout.findViewById(R.id.buttonMyAlertDialogCancel);
buttonMyAlertDialogCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertNegative.cancel();
rowSeleceted = -1;
}
});
builderNegative.setView(dialoglayout);
alertNegative.show();
}
xml.file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonSaturation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/RefuseAssigned1" />
<Button
android:id="@+id/buttonNoZone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/RefuseAssigned2" />
<Button
android:id="@+id/buttonLiquidity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/RefuseAssigned3" />
<Button
android:id="@+id/buttonMyAlertDialogCancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/RefuseAssigned4" />
</LinearLayout>
非常感謝!這是真的......在閱讀你的答案之前,我試着做出這種改變,它的工作原理。 真的,非常感謝您的解答:D – user3212414