Show a Toast Message | Android App Development Tutorial #1
What will I Learn?
Requirements
Procedure
- Now open the activity_main.xml file as shown the tree structure here and click on split button to show the code and design at the same time.
- Now replace the code as given here it include a Linear Layout and a Button inside it with the id message_btn
<LinearLayout 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"
tools:context=".MainActivity"
android:gravity="center">
<Button
android:id="@+id/message_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Message"/>
</LinearLayout>
- Open the MainActivity.java file as shown the RED line in this mockup
- Insert the Button click code after this line
setContentView(R.layout.activity_main);
here is the button click code
//Its a code for a button click that we declare in activity_main.xml file
findViewById(R.id.message_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Its a code to show the message on the screen
Toast.makeText(MainActivity.this, "Hello Hive", Toast.LENGTH_SHORT).show();
}
});
- Picture of all code setup in MainActivity.java
- Now connect you mobile device and lets test the app make sure the Developer Option is on and the USB Debugging is enabled.
- Click on the play button to run the app
Final Result
| App on Mobile | Button Clicked |
|---|---|
Follow | Upvote | Share
About me
Hello Friends I am Muhammad Faisal Amin. My country is Pakistan. nI live in a city of Pakistan named Faisalabad. I love my country.
I am 21 years old in 2020.
I study in Software Engineering in University of Agriculture Faisalabad Main Campus it also knows as UAF.
Its a very beautiful University and the biggest University in Asia.
I am also having experiences in MObile App Development using Java Android and Flutter also.
Its my passion to develop quality app for both iPhone and Android Mobiles.
Leave Show a Toast Message | Android App Development Tutorial #1 to:
Read more #hive-148441 posts
Best Posts From uafappdevelopers
We have not curated any of uafappdevelopers's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From uafappdevelopers
- Rate list of City Faisalabad Pakistan 27-09-2020
- Rate list of City Faisalabad Pakistan 26-09-2020
- Rate list of City Faisalabad Pakistan 25-09-2020
- Rate list of City Faisalabad Pakistan 25-09-2020
- Rate list of City Faisalabad, Pakistan 24-09-2020
- Dinner at a Village Dhaba || Chicken Tekki
- Rate List in Pakistan, Faisalabad 22-09-2020
- Random Photo shoot of Nature || No Editing
- Beautiful Cloud Natural Pictures || Flying Birds Scene || No Editing
- Keep the Nature Clean || Our Mission
- Corona Tiger Force on Duty | Awareness Mesaage
- Distribution of face mask | Corona Tiger Force | COVID-19
- Flowers are always beautiful | My Father brings flowers for spreading accent in home
- Distribution of face mask | Tiger force | COVID-19
- Meet my Nephew | Cool Guy
- Aware people for COVID-19
- Village Dog
- Nature scene today
- Show a Toast Message | Android App Development Tutorial #1
- PUBG Mobile Arena Training | 22 Kills | PkGhostWarrior