How To Create List in Android Using ListView


How To Create List in Android Using ListView Thumbnail

Here I will start From The Basic View and Examples of Android. here we will discuss the most useful and important Part for most of the Android App That is How to  Implement ListView in Android App and How To Set a Listeners in That ListView.

I have Previously Posted an Article On Customized RecyclerView For That ClickHere

Below Screen Shot Is the Final Output Of Our Tutorial
Final output of How to create List in Android
Final Output
  1. Create a new project by going to File ⇒ New Android Project. Fill all the details and name your activity as MainActivity.
  2. Once the project is created open your activity_main.xml file and Add Below Code.


<?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android=""  
After this, You Can See an Output Shown in Below Screenshot

Layout Output

3. Now Open Your And Add Below Code in it.

I have Used ArrayList and ArrayAdapter in This Scope to Populate Our List With Data

ArrayList:- The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as is an implementation of java.util.List that’s backed by an array. You can use it anywhere you would use a java.util.List. E.g. where you need to maintain an order of a collection of objects where duplicates are allowed.

ArrayAdapter:-  is an Android SDK class for adapting an array of objects as a data source. Adapters are used by Android to treat a result set uniformly whether it’s from a database, file, or in-memory objects so that it can be displayed in a UI element. The ArrayAdapter is useful for the latter. Use it anywhere you would use an Adapter.


 import android.os.Bundle;  
 import android.view.View;  
 import android.widget.AdapterView;  
 import android.widget.ArrayAdapter;  
 import android.widget.ListView;  
 import android.widget.Toast;  
 import java.util.ArrayList;  
 import java.util.List;  

 public class MainActivity extends AppCompatActivity {  
   //Creating Variable Of ListView  
   ListView list_city;  

   protected void onCreate(Bundle savedInstanceState) {  

     //Connecting Our ListView Id With Java Variable  

     /*Creating a List Variable and Intializing   
     it by ArrayList Beacuse ArratList is its Parent Class*/  
     List<String> city=new ArrayList<>();  

     //Adding Values to list  

     //Passing that list data into ArrayList So that we can Show it in Our List  
     ArrayAdapter cityadap=new ArrayAdapter(this,android.R.layout.simple_list_item_1,city);  

     //Finally Set the adapter into our listview  

     //setting a listener into our listview you can use intent also by checking which item is clicked  
     list_city.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
       public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {  
          Toast.makeText(MainActivity.this,"You clicked item no.:- "+position,Toast.LENGTH_SHORT).show();  


4. Now finally run Your Project

You Will See A Below Output

Final Output Before Click of creating Listview in android
Final Output After Click of creating Listview in android

For More Tutorial Share And Subscribe to my Blog So you will get all the updates in your email, We Never Spam.

Thank You



  1. Anonymous September 20, 2017 Reply

Add a Comment

Your email address will not be published. Required fields are marked *