I'm trying to get a pop-up window (modal window) open when I click a button. I have no idea how it works in Java, I've seen a lot of tutorials and can't figure it out. Here is my button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<LinearLayout
android:layout_margin="50dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
//This is the button that should open a modal window
android:id="@+id/btnfruit"
android:background="@mipmap/iconfruit"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="100dp"
android:background="@mipmap/vegetable"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="200dp"
android:background="@mipmap/protein"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="300dp"
android:background="@mipmap/dairy"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="400dp"
android:background="@mipmap/grain"
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageView
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"/>
</RelativeLayout>
this is the modal window.
<?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="400dp"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="5dp"
>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="X"
android:textStyle="bold"
android:layout_gravity="end"
android:gravity="center"/>
<Button
android:id="@+id/btnaddfruit"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Add Item"/>
</LinearLayout>
I guess my question is, what goes on MainActivity.java or can I code it straight to the button? Thank you in advance for your time and answers.