Develop Android Apps, Listview with Toast Example
Next Tutorial
Coding a Sliding Drawer

Prev Page
View All Tutorials


Android Tutorial, ListView with Toast Message

If you are just arriving at this page; and you are not familiar with creating Android Apps,we suggest you begin with our tutorials introduction: About Our Tutorials. From there follow along with each tutorial lesson.


This is the App - ListView with Toast Message
Example android, ListView Toast App Photo
When You Click on "My Android Codes", the Toast Message
appears that reads "My Android Codes selected"

 Array for ListView Example

Where - How - Why To Use a ListView with Toast Message

As you learned in our previous tutorial, ListView is a code class for a scrollable user interface, usually containing one or two rows of data per sectioned item. In its simplest form, the List Activity class of ListView method provides a single rowed layout which can be used to add your data rows.

In this tutorial we will code a ListView that also has one row of data, and also includes the toast widget which will populate a small dialog box with the name of the row item when you click the data in any row.

Because we are using the ListView element in our layout file; we can also add some additional attributes that are available for ListView. We will add the attributes that allows us to add a divider after each row, adjust the height of the divider, and add any color to it that we want to.

As with our previous tutorial, this ListView method will also use the android built-in code method for a single row in our listview layout using this code - android.R.layout.simple_list_item_1
This code is a android default built-in code for ListViews. It means that the layout will have one row - item_1. If it had read item_2, then the row would have 2 items, meaning 2 rows per each section. Our app has 1 row per each section.

For our data, we added words so to get enough rows that our listview becomes scrollable. Scrolling is also built-in with the ListView code class. Once the rows exceed the physical parameter of our view display, they will scroll so you can see all the rows.

Additional Reading at Android Developer website:
ListView - ListActivity

Creating - Naming Your App Using AIDE

When creating your app,(from left menu) choose:
Create New Project;
Then, choose
New Android App(gradle, android Java/xml)
or
Hello World App Java/xml
if your using the original version of AIDE

You can name your app whatever you like; if your using the name as shown in our example code use;

ListViewToast for the App Name and,
for the package name(next line) use:
com.aac.examplelistviewtoast

The Coded Pages

Code for the app - ListViewToast

For this app we need to edit these pages;

1 layout file, main.xml; located at res/layout/main.xml, already created, just replace the code on this page with the code from our Example Code section and save the page.

The code in the ListView element has the divider height and divider color which we can adjust as we want.
For height we used the code android:dividerHeight="2dp", and for the divider color, use the code, android:divider="#212121", as shown in this image.
Layout for ListView with Divider Height and Divider Color
1 java class page; MainActivity.java; located at app/src/java/MainActivity.java, already created; we have to copy and replace the code on this page with the code from our Example Code section. Save the page once the code is pasted.

The java page has our import codes. The import codes must be coded in your java page for each code class your implementing.

Coding import statements android
The java page also has the array containing our items for each row in our ListView. And, the array is attached and populated into our view using the array adapter.
 Android example, Array for ListView


1 strings file, strings.xml required for this App: The string file located at res/values/strings.xml has the required app_name string for the app name.

Just remove the string that reads - hello_world, or copy/paste the code from our Example Codes section. Save the page.


EXAMPLE CODE - Code For This Tutorial

JUST copy the code for this tutorial App Name is 'ListViewToast - located at AppProjects/ListViewToast in AIDE, open the AIDE app, then open App Projects, THEN select the 'ListViewToast', app from your files hierachy(left menu); then click on any file from the app, like strings.xml

Make sure at top of page, the app name 'ListViewToast' is there next to AppProjects like so: AppProjects/ListViewToast, then you know you have the proper App.

Once a file is in the editor, you can edit, save it, then RUN your APP, Install, and Open your app.


Make sure you SAVED EACH PAGE,(or choose automatic saving in AIDE settings) before you RUN your code. SAVE, RUN, INSTALL, OPEN, your App. Once it has been installed on your tablet, you can open it Simply by Clicking on the Android little green App Icon,with the wording 'ListViewToast' on your tablet. It will be with your other installed apps.

If you make further changes to this App, you need to SAVE, RUN, UPDATE, INSTALL, OPEN the app.

Example Code App - ListViewToast :
Use Mouse To Copy Paste the Code


This free script provided by
JavaScript Kit

Share This Page


AIDE for creating Android Apps on your tablet or cell phone(android).
Free and Paid.
GoTo Aide

ANDROID STUDIO - for creating Android Apps on your desktop computer.
Free to Install and Use
GoTo Android Studio Learn more - Android Studio


The Java XML files we code(example codes) and the Android Apps we create in our Free Tutorials are compatible with Android Studio and AIDE. Just choose Java XML as your Programming Language.


AndroidAppCoding.com, All Rights Reserved