Basic Listview


    After you get your hands on Android, you will find the most useful widget is the ListView. You may also feel that it's required on every activity. Android being Open-Source, it is the most flexible mobile platform out there. 

    Everyone, wants to customize it according to their taste. You would hardly see an app that uses the default look and feel of the widgets. But with flexibility comes complexity.This is a basic listview example for android 

1.First create new android application project
2.Then use this codes for implementing

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>


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[] {
"India",
"Pakistan",
"Sri Lanka",
"China",
"Bangladesh",
};
/** Called when the activity is first created. */
@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_1countries);
ListView listView = (ListView) findViewById(R.id.listView1);
// ArrayAdapter indirectly implements ListAdapter interface
listView.setAdapter(adapter);
}

}

Output Screen

Previous
Next Post »

1 comments:

Write comments
Unknown
AUTHOR
February 27, 2014 at 11:36 AM delete

Good Tutorial................

Reply
avatar