Thursday 10 April 2014

Listview Tutorial

Listview Tutorial    

In this tutorial i will be demostrating to build a simple listview 

.In this project we are going to create a simple listview .

1)Create a new android application project in eclipse 

2)Then after craeting a new project you have to edit the activity_mail.xml file , As shown below

activity_main.xml

<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"
  
    tools:context=".MainActivity" >

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

</RelativeLayout>


   3)After editing the activity_main.xml file now you have to code the main activity  file as shown below

Mainactivity.java

package com.example.listviewbasic;

import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
String[] countries = new String[] {
"apple",
"grapes",
"orange",
"mango",
"water melon",

};


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
     
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);       
        ListView listView = (ListView) findViewById(R.id.listView1);
       listView.setAdapter(adapter);       
    }
}

 4)Now the basic listview is ready.
                                                           


1 comment:

Total Pageviews

Contact Form

Name

Email *

Message *

Mobile App Developer