Android Simple ListView example tutorial

How to Use static listView in android.

ListView is used to show data items into vertically form at one by one simulation so user can easily read and learn them. Listview comes into composite type in android widgets. So here is the complete step by step tutorial for Android Simple ListView example tutorial.

android-project-download-code-button

Android Simple ListView example tutorial.

Code for MainActivity.java file.

 package com.android_examples.com.listviewsimple;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

 ListView listView;
 String[] listValue = new String[] {"Android Examples","Android Studio","SDK Manager","Eclipse"
 ,"Java","JDK"};
 
 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 listView = (ListView)findViewById(R.id.listView1);
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_2, android.R.id.text1, listValue);
 
 listView.setAdapter(adapter); 
 
 
 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.listviewsimple.MainActivity" >

 <ListView
 android:id="@+id/listView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 
 >
 </ListView>

</RelativeLayout>

Screenshot:

Android Simple ListView example tutorial

CLICK HERE TO DOWNLOAD Android Simple ListView example tutorial PROJECT.