【发布时间】:2018-06-14 00:56:56
【问题描述】:
来自 VB 世界,我今天了解到,对话框在 Java 中不是模态的。我的任务是使用适用于 Android 摩托罗拉设备的 Android Studio 将我们在 VB.net 中为基于 Windows 的摩托罗拉设备编写的程序转换为 Java。 我正在尝试使其类似于 Windows 中的表单。 我在一个有几个提示输入的消息框的表单中。 我试过做java,但注意到对话框并不总是等待响应。 我已经读过使用 dialogfragments 可以完成我想要做的事情。 这是我在第一个对话框中使用的 XML。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackgroundGray"
>
<TextView
android:id="@+id/theText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Holding Text"
android:textAlignment="center"
android:textColor="@color/colorBlack"
android:textSize="30dp" />
<Button
android:id="@+id/buttonYes"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/message"
android:layout_margin="8dp"
android:onClick="onClickYes"
android:text="Yes"
android:textSize="26dp" />
<Button
android:id="@+id/buttonNo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@id/message"
android:layout_margin="8dp"
android:onClick="onClickNo"
android:text="No"
android:textSize="26dp" />
</RelativeLayout>
这是我调用对话框的方式。
final Dialog dialog = new Dialog(ReturnAreaActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.dialog_location);
dialog.setTitle("New Location Setup");
TextView message = (TextView) dialog.findViewById(R.id.theText);
message.setText("Is this location a Pick Bin");
Button buttonYes = (Button) dialog.findViewById(R.id.buttonYes);
Button buttonNo = (Button) dialog.findViewById(R.id.buttonNo);
dialog.show();
对需要进行哪些更改才能将对话框转换为 dialogFragment 有疑问。我很欣赏任何人都可以摆脱的清晰。此外,dialogFragments 的调用将在循环期间完成
谢谢
【问题讨论】:
标签: java