I'm newbie in Xamarin. I'm creating a simple application with Xamarin. I have a table view in my layout. Each row of table view displays a modal window. For example the first row is used to get the full name of the user. I want to display the modal window shown (rightside) in the given figure.
I have created a Layout for the same as given below
<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"
android:minWidth="25px"
android:minHeight="25px">
<EditText
android:inputType="textPersonName"
android:layout_width="200dp"
android:layout_height="55px"
android:id="@+id/txtFirstName"
android:ellipsize="none"
android:gravity="fill_horizontal"
android:hint="First Name"
android:height="55dp"
android:layout_marginTop="100dp"
android:layout_gravity="center_horizontal"
android:textColor="#000000" />
<EditText
android:inputType="textPersonName"
android:layout_width="200dp"
android:layout_height="55px"
android:id="@+id/txtLastName"
android:ellipsize="none"
android:gravity="fill_horizontal"
android:hint="Last Name"
android:height="55dp"
android:layout_marginTop="25dp"
android:layout_gravity="center_horizontal"
android:textColor="#000000" />
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:minWidth="25px"
android:minHeight="25px"
android:layout_marginTop="25dp">
<Button
android:text="Save"
android:layout_width="100dp"
android:layout_height="55px"
android:id="@+id/btnSave"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:layout_marginTop="0dp"
android:textColor="#000"
android:layout_marginLeft="165dp" />
</RelativeLayout>
</LinearLayout>
And my code to display popup
tblrName.Click += delegate
{
//Want to display the modal window here.
};
I tried to set the layout using setContentView()
but it opens a new window while I want to display the modal window in same screen itself.
Can anybody help me to achieve this?
Xamarin. Forms provides support for modal pages. A modal page encourages users to complete a self-contained task that cannot be navigated away from until the task is completed or cancelled.
Use AlertDialog
.
In your click event, try this:
var alert = new AlertDialog.Builder(this);
alert.SetView(LayoutInflater.Inflate(Resource.Layout.Modal, null));
alert.Create().Show();
To get values from AlertDialog
, you could keep a reference to the EditText
in the dialog. And then, in your Save button click event, simply call EditText.Text
to get the value.
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