Monday, September 24, 2012

Simple ListView in Android | Simple ListView Example in Android | Simple List Item Demo In Android


Hello Friends,
    It's a very simple demo of ListView in android using android.R.layout.simple_list_item_1.


1-Print Screen

2-MainActivity.java
package com.example.listview;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = (ListView) findViewById(R.id.list1);
String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, days);
list.setAdapter(adapter);
}
}
3-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" >
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.