What is the best way to create a modal text entry dialog for android?
I want to block until the user enters the text and hits the ok button, then extract the text from the dialog, just like a modal dialog in awt.
Thanks!
Try this:
final Dialog commentDialog = new Dialog(this);
commentDialog.setContentView(R.layout.reply);
Button okBtn = (Button) commentDialog.findViewById(R.id.ok);
okBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do anything you want here before close the dialog
commentDialog.dismiss();
}
});
Button cancelBtn = (Button) commentDialog.findViewById(R.id.cancel);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
commentDialog.dismiss();
}
});
reply.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff">
<EditText android:layout_width="fill_parent"
android:layout_gravity="center" android:layout_height="wrap_content"
android:hint="@string/your_comment" android:id="@+id/body" android:textColor="#000000"
android:lines="3" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/ok" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="@string/send" android:layout_weight="1"
/>
<Button android:id="@+id/cancel" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:text="@android:string/cancel" />
</LinearLayout>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With