Android Listview From Array

Android Listview ia group of several item. It display of  scrollable list. This list automatically add in the list item form array. We use locally array or use database like json. Here we data insert form arraylist and sent to data adapter view. This data  can shows different whay like list view, grid view and spinner etc. This Listview and Gridview are subclasses for Adapter, Which save data from another source and view in list.

Android array listview
Android array listview

It is a simple android listview from array. We can customize any time from arraylist.



First Create Project in android studio

Android XML CODE:

<?xml version=“1.0” encoding=“utf-8”?>


















      tools:layout_editor_absoluteX=“8dp” />






Java Code:

package com.layout.apps.listviewfromarray;



import android.content.DialogInterface;

import android.os.Bundle;



import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

  ListView listView;


  protected void onCreate(Bundle savedInstanceState) {




      // Define string array.

      final String[] listValue = new String[] {“One”,“Two”,“Three”,“Four”,“Five”,“Six”,“Seven”,“Eight”,“Nine”,“Ten”,“Eleven”,“Twelve”,“Thirteen”,“Fourteen”,“Fifteen”,

              “Sixteen”,“Seventeen”,“Eighteen”,“Nineteen”,“Twenty”}; // array list


          listView = (ListView)findViewById(;  //listView string show

          ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_item,, listValue);



      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { // listview onclick for chack string position


          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


           //—————–Alert Dialog ———————————————————

              AlertDialog.Builder sm = new AlertDialog.Builder(MainActivity.this);

              sm.setTitle(listValue [position].toString());

              sm.setMessage(“Are you sure?”);

              sm.setPositiveButton(“YES”, new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {




              sm.setNegativeButton(“NO”, new DialogInterface.OnClickListener() {


                  public void onClick(DialogInterface dialog, int which) {





              AlertDialog alert = sm.create();



              //toast for onClick item show position wise

              Toast toast = Toast.makeText(getApplicationContext(),listValue [position].toString(),Toast.LENGTH_SHORT);






About onlinetech

Leave a Reply

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