ListView


 

  1. Static ListView
  2. Dynamic ListView
  3. Static ListView using ListActivity
  4. Dynamic ListView using ListActivity
  5. ListView using ListFragment
  6. Static ListView using Custom ArrayAdapter
  7. Dynamic ListView using Custon ArrayAdapter
  8. Custom ListView using BaseAdapter
  9. Custom ListView using SimpleAdapter
  10. Custom ListView using POJO Class
  11. ListView using SimpleCursorAdapter
  12. ListView using CursorAdapter
  13. Get Selected Item in Listview
  14. Adding Runtime Values in ListView
  15. Listview Custom ListItem Divider
  16. ListView Custom Selection OnItem
  17. ListView with ActivatedItems
  18. ListView with Single Choice
  19. ListView with Multi Choice
  20. ListView with SelectionMode
  21. ListView with Sections
  22. ListView with View
  23. ListView Save & Restore Scroll Position
  24. ListView with OnScrollListener
  25. ListView with StartActivityForResult
  26. ListView inside ScrollView

 

1. Static ListView
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> values -> Create new xml file, arrays.xml and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

listview

Download_button

 

2. Dynamic ListView
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 :Open src -> package -> MainActivity.java and add following code :

Step 3 : Open AndroidManifest.xml and add following code :

ScreenShot:

dy_listview

Download_button

 

3. Static ListView using ListActivity
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

listview_list

Download_button

 

4. Dynamic ListView using ListActivity
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 :Open src -> package -> MainActivity.java and add following code :

Step 3 :Open AndroidManifest.xml and add following code :

ScreenShot:

dy_listview_listarray

Download_button

 

5. ListView using ListFragment
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> layout ->Create new xml file, list_fragment.xml and add following code :

Step 5 : Open src -> package -> Create new class, MyListFragment.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

listfrag listfrag2

Download SourceCode

 

6. Static ListView using Custom ArrayAdapter
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 2 : Open res -> layout ->Create new listitem_row.xml and add following code :

Step 4 : Open src -> package -> MainActivity.java and add following code :

Step 5 : Open src -> package ->Create new class CustomListAdapter.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

listview_cusarray listview_cusarray2

Download_button

 

7. Dynamic ListView using Custom ArrayAdapter
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout ->Create new listitem_row.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package ->Create new class CustomListAdapter.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

dy_listview_custom dy_listview_custom2

Download_button

 

8. Custom ListView with BaseAdapter
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> layout -> Create new listitem_row.xml and add following code :

Step 5 : Open src -> package -> Create new class CustomListAdapter.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

list_base1 list_base2 list_base3

Download SourceCode

 

9. Custom ListView using SimpleAdapter
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

list_simple1 list_simple2

Download SourceCode

 

10. Custom ListView using POJO Class
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open res -> layout -> Create new xml file, listitem_row.xml and add following code :

Step 4 : Open src -> package -> MainActivity.java and add following code :

Step 5 : Open src -> package -> Create new java class, CustomListAdapter.java and add following code :

Step 6 : Open src -> package -> Create new java class, NumberHelper.java and add following code :

Step 7 : Open AndroidManifest.xml and add following code :

ScreenShot:

 dy_list_pojo

Download SourceCode

 

11. ListView using SimpleCursorAdapter

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open res -> layout -> Create new xml, list_child.xml and add following code :

Step 4 : Open src -> package -> MainActivity.java and add following code :

Step 5 : Open src -> package -> Create new class, SqlLiteDbHelper.java and add following code :

Step 6 : Open src -> package -> Create new class, AndroidVersionHelper.java and add following code :

Step 7 : Open AndroidManifest.xml and add following code :

Step 8 : Open build.gradle(Module: app) and add following code :

ScreenShot:

 list_simplecursoradapter

Download SourceCode

 

 

12. ListView using CursorAdapter

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open res -> layout -> Create new xml, list_child.xml and add following code :

Step 4 : Open src -> package -> MainActivity.java and add following code :

Step 5 : Open src -> package -> Create new class, SqlLiteDbHelper.java and add following code :