CustomListView

     "Custom ListView"   

     Hello friends, In previous blog we are studied about ListView with ArrayAdapter. Now in this block weare going to study about custom ListView using BaseAdapter.

     In previous blog we have created one Simple ListView that contains only text. The custom ListView means creating custom layout of list items. In this tutorial we are going to adding image, text and button in one list row.

     Before implementing custom ListView lets know about BaseAdapter. In Android, an Adapter is a bridhe between UI component and data source (Like, ArrayList, Array etc) that help us to fill data in UI components.

    To customize ListView we can create own Adapter class with own layout file by extending BaseAdapter class. BaseAdapter can be used for implementing custom ListView, GridView , Spinner etc.

    The following code snippet shows the overrid methods of BaseAdapter class.




    In above code snippet shows an structure and uses of methods of BaseAdapter. Now lets see one example of BaseAdapter.

    In below example we display list with ImageView, TextView and Button to understand how to implement custom ListView.



   Now create a layout file of above class as follow.



   After creating above two file its time to add listview in activity_main.xml file and set above custom adapter to ListView in MainActivity.java file. Lets see the following code snippet

  Copy and paste the following code in MainActivity.java file



In above code "MainActivity.java", I have created two arraylist. One for list items which is string type and another one for images which is integer type arraylist. And this two arraylits are passed to the custom adapter class ie "MyAdapter.java".

  Now create the layout file of MainActivity.java class, It contains ListView. See the following code.




  Done! Now run your code and see the output. If having any query don't be hesitate, type your query in comment box.
Enjoy coding!😊
Click Here To Download Full Code

Comments

  1. Replies
    1. Thank you. Your support is motivating to me for posting and sharing my knowledge with all.

      Delete
  2. ohhh swapnil sir............you did very well.
    Thank You!!!!!!!!!

    ReplyDelete

Post a Comment

Popular posts from this blog

SQLite with RecyclerView

Update data in SQLite

Swipe to delete RecyclerView Item