Phone: +66-94-257-9379

Beatrice Krell
2016-04-14 16:04:17
Android ExpandableListView, Android ListView, Android ListView Icon, Android ListView Image, Fitness Manager
1 Comment

Since the Fitness Manager App is an app for organizing and scheduling the personal workout, I needed to implement powerful ListViews, which provide the user with helpful information and statues. Still the ListViews must be kept clear. Additionally the elements of the ListViews should be made graphical appealing with an Android ListView Image or an Android ListView Icon. And that is the way how I put my requirements into Java code:

1. The layout.xml of the activity containing the Android ListView is very simple.


2. In order to realize my design concept for the Android ListView, I had to insert a layout.xml and a Java class file, where I did define the elements of the single list items of the Android ListView.


As displayed in the code snippet of the layout.xml I did use a RelativeLayout with an id and a background image. On the left side of the parent layout I did insert an ImageView. To the right side of the ImageView I did define two TextViews with different text styles. On the right side of the parent layout I did add another ImageView. The values of all elements in the ListView items are dynamic except of the last ImageView. The source for this ImageView is already set in the layout.xml and received from the rescources.

In the Android Studio Designer the XML layout definition of the ListView items is finally displayed like this:


The Java class for a ListView item contains variables, constructors, getter and setter functions for the dynamic elements. Whatever is needed for the ListView item.


3. In Android every ListView needs an adapter. If you just want to display a simple ListView with ListView items only containing one simple String value, you just need to define a simple ArrayAdapter in the onCreate function of your activity. But if you want to use your own design for the items of the ListView, you also have to define a separate adapter in a Java class file extending the class ArrayAdapter.


The adapter class needs to contain a constructor and the methods getItemId and getView. In the getView funtion the elements of the ListView item with dynamic values are set. First a LayoutInflater must be created in order to get the view. The values for the ListView elements are retrieved from the ArrayList and assigned to the ImageView and TextViews by using the corresponding setter functions of the Java class for the ListView elements.

4. At least the ListView and the adapter have to be instantiated and assigned in the onCreate function of the activiy.


After initializing the ListView, an ArrayList is defined and filled with the required data and bitmaps in a for loop. Then the adapter has to be defined and assigned to ListView, which then gets registered the context menu. The implementation of the function setOnItemClickListener of the ListView needs to be handled in the onCreate method of the activity as well.

5. Most often the appearance of the ListView changes while the activity is running. There are several examples like a new element is added to the ListView, an existing element of the ListView is deleted or a text in one of the TextViews can be changed by another foreground activiy. Then the ListView must be reloaded. This is handled in the onResume function of the activity.


The implementation of the onResume method of the activity is similar to the implementation of the onCreate function. The ArrayList is defined and filled with the required data and bitmaps again. The global variables of the ListView and the adapter are not defined again here, instead the adapter is cleared and the elements of the ListView are added one by one. The call of the function notifyDataSetChanged at the end notifies the attached observers that the underlying data has been changed and any view reflecting data set should refresh itself.

This kind of ListView designs can of course also be used for other types of ListViews like the Android ExpandableListView.


I hope you did enjoy reading my Blog about the implementation of ListView Layouts for Android devices with Android ListView Image and Android ListView Icon.

If you have any questions, any improvement suggestions for the implementation (I mentioned that this is my first Android App) or any improvement suggestions for my English, I really would appreciate if you can leave me a comment.

And I would even more appreciate if you like to check out the 'Fitness Manager' App in the Google Play Store or the 'Fitness Manager' App in the iTunes Store. See you.

Follow us on
Google Plus

Contact Details

Telephone: +66-94-257-9379

Hot and quiet place with WiFi

Koh Phangan,