Android Array Adapter

Android Array Adapter

In Android Array Adapter , any time we want to show a vertical list of scroll able items we will use a ListView which has data populated using an Adapter. The simplest adapter to use is called an ArrayAdapter because the adapter converts an ArrayList of objects into View items loaded into the ListView container.

The ArrayAdapter fits in between an ArrayList (data source) and the ListView (visual representation) and configures two aspects:

  • Which array to use as the data source for the list
  • How to convert any given item in the array into a corresponding View object

Note as shown above that there are other data sources besides an ArrayAdapter such as the CursorAdapter which instead binds directly to a result set from a Local SQLite Database

You can use this adapter when your data source is an array. By default, ArrayAdapter creates a view for each array item by calling toString() on each item and placing the contents in a TextView. Consider you have an array of strings you want to display in a ListView, initialize a new ArrayAdapter using a constructor to specify the layout for each string and the string array –

ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.ListView,StringArray);

Here are arguments for this constructor −

  • First argumentthis is the application context. Most of the case, keep it this.
  • Second argument will be layout defined in XML file and havingTextView for each string in the array.
  • Final argument is an array of strings which will be populated in the text view.

Once you have array adapter created, then simply call setAdapter() on your ListView object as follows −

ListView listView = (ListView) findViewById(;listView.setAdapter(adapter);

Step By Step Tutorial

Step 1 : Open the Android studio.

Step 2 :  Click on New Project option

Step 3 :  Give the name of your application. (for example: ArrayList).  Give the Company domain name or you can leave it as.  And give the project location.

Step 4.     After New Project Name Screen there come where you have to choose the particular android version. It implies/ tells us the compatibility of our project in different android platforms. To Study about Available Android Version Click here.

Step 5. In this part you have to select from the provided templates and the result project will be as similar that is displayed on the particular template as follows. It Act as the MainActivity of this Project.


Here we Select the Empty Activity where we can do all the coding.

Step 6.        Give Activity Name, Layout Name, and title to selected Activity. In this I name It “ListDisplay” and the layout name as “activity_list_display”

Step 7. After you click on finish button on the last screen then the android will start to build the empty project for you. where you have to design your own layout and implement your own function. once finish it redirect us to the page. where all the coding part is done.

Step 8. Now we are working on the Layout part where we create a list view to display the windowArray List. as shown in the snapshotI use Simple List View to implement.


Step 9.

To run the app from Android studio, open one of your project’s activity files and click Run   icon from the tool bar. Android studio installs the app on your AVD and starts it and if everything is fine with your set-up and application, it will display following Emulator window –

Here i use the android phone to run the project because Android Emulator takes so much time to process and sometimes it stuck in the process.

process to run Android project in android phone directly via USB Cable

1. Install the drivers of you phone known as MTP(MEDIA TRANSPORT PROTOCOL) from official site.

2.Enable Development mode through 7 times click on version under About Phone Setting.

3.Now open development mode and enable the usb debugging.

that’s it now your android studio automatically pick your mobile details. until unless the android SDK is not correctly installed.



 import android.os.Bundle;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;
 public class ListDisplay extends AppCompatActivity {
      //Array of String
      String[] windowArray = {"Win XP","Win 7","Ubuntu","Mac OSX","Win 8","Win 8.1","Win 10","Linux","Red Hat"};
     protected void onCreate(Bundle savedInstanceState) {
         ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, windowArray);
         ListView listView = (ListView)findViewById(;


<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android=""


Now Save your Project and RUN IT the output is same as the


String[] windowArray = {"Win XP","Win 7",      String[] windowArray = {"Win XP","Win 7",
"Ubuntu","Mac OSX","Win 8","Win 8.1",            "Ubuntu","Mac OSX","Win 8","Win 8.1",
"Win 10","Linux"};                                  "Win 10","Linux","Red Hat"};


it took only in seconds to implement the changes because after 2.1.1 update in android studio it enables insta RUN Technique. so if you do any changes then there is no need for clear and rebuild the project just click on RUN button and done.

Post a comment

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