Home » Android » Static ListView – android

Static ListView – android

Static ListView Creation in Android

Step 1 : Select File -> New Project -> Project Name

Step 2 : Open res -> layout -> activity_main.xml  add following code :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:entries="@array/datalist" />
    </LinearLayout>


</android.support.constraint.ConstraintLayout>

 

Step 3 : Open src -> package -> MainActivity.java and add following code :
package af.appjow;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
Step 5 : Open res ->values ->strings.xml and add following code :
<string-array name="datalist">
        <item>Item 1</item>
        <item>Item 2</item>
        <item>Item 3</item>
        <item>Item 4</item>
        <item>Item 5</item>
        <item>Item 6</item>
    </string-array>

 

 

Step 6 : Output:
android listview

android listview

 

Download code

 

 

 

Leave a Reply

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