Show Modal Window in Xamarin

I am new to Xamarin. I am creating a simple application with Xamarin. I have a table view in my layout. Each row of the table displays a modal window. For example, the first line is used to get the full username. I want to display the displayed modal window (rights) in this figure. Question

I created a layout for the same as 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 a 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 on the same screen.

Can someone help me achieve this?

+6
source share
1 answer

Use AlertDialog .

In the click event, try the following:

 var alert = new AlertDialog.Builder(this); alert.SetView(LayoutInflater.Inflate(Resource.Layout.Modal, null)); alert.Create().Show(); 

To get values ​​from AlertDialog , you can save the EditText link in the dialog box . And then, by clicking the "Save" button, just call EditText.Text to get the value.

+14
source

Source: https://habr.com/ru/post/955609/


All Articles