Prepared and tested with Android Studio and Java (2018-04-03)
Table of contents
Project description
With this application we can practise how to implements list view - an Android list component.
Requirements:
- There are four buttons on the main screen
- One string item
- Simple item layout
- Two strings item
- Custom
- When One string item is pressed a list of items displayed by default one-line list cell style android.R.layout.simple_list_item_1 should be visible. To complete this you can use material 1 (first part) from Materials section.
- When Simple item layout is pressed a list of items displayed by modified one-line list cell style should be visible. In this case we have one string (TextView) in each cell but its properties can be specified in XML file. To complete this you can use material 2 and 3 from Materials section.
- When Two strings item is pressed a list of items displayed by default double-line list cell style android.R.layout.simple_list_item_2 should be visible. To complete this you can use material 4 and 5 from Materials section.
- When Custom is pressed a list of items displayed by custom style should be visible. To complete this you can use material 1 (second part), 6 (part 4. Custom adapter implementations) and 7 from Materials section.
- In each case when list item is selected a message of Toast type should be displayed with list item's text(s) as its contents.
- In Extra: 8 from Materials section you have a lot of informaiton about various list view problems, solutions and possible approaches or in Extra: 9 - Extra: 10 how to use ImageButton.
All the information needed to complete this project can be found in Materials section.
How it should work
- When started a main view (activity) should be visible with a set of buttons defined in requirements (Project description section)
- Press One string item button. A simple list with one-line text cells should be visible
- When list item is selected (touched) a toast message should be displayed
- Press Simple item layout button. A simple list with one-line text cells and modified view should be visible
- Press Two string item button. A list with two-line text cells should be visible
- When list item is selected (touched) a toast message should be displayed
- Press Custom button. A list with custom cells should be visible
Source code
For this project the following files were created
- CustomActivity.java
- CustomArrayAdapter.java
- MainActivity.java
- OneStringItemActivity.java
- SimpleItemLayoutActivity.java
- TwoStringsItemActivity.java
- activity_custom.xml
- activity_main.xml
- activity_one_string_item.xml
- activity_simple_item_layout.xml
- activity_two_strings_item.xml
- AndroidManifest.xml
- custom_layout.xml
- simple_item_layout.xml
- strings.xml
Materials
- 1: ListView, pierwsze kroki
- 2: ListView - przykład widoku listowego
- 3: Android List View
- 4: Using simple_list_item_2 with an ArrayAdapter (Android)
- 5: Android – List with a custom layout and complex ArrayAdapter
- 6: Using lists in Android (ListView) - Tutorial
- 7: How to create custom Listview in Android
- Extra: 8: Using lists in Android with ListView - Tutorial
- Extra: 9: Android ImageButton example
- Extra: 10: Android Custom ListView with ImageView EditText and Button