Simple "Hello World" dialog example in Android studio.
In my case I started new application, and left everything by default.
In content_main.xml (in my case it is located in \app\src\main\res\layout\content_main.xml) I added button:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:layout_below="@+id/textView" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="53dp" android:nestedScrollingEnabled="false" android:onClick="testMessage" />
Here notice "android:onClick="testMessage""
Then in MainActivity.java (in my case it is located in \app\src\main\java\com\example\smi\msearch\MainActivity.java) I created method like:
public void testMessage(View view) { AlertDialog builder = new AlertDialog.Builder(MainActivity.this).create(); builder.setTitle("Yo!"); builder.setMessage("This is a test!"); builder.show(); }