Simple List Activity

Java Class of src folder where :



import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.ClipData.Item;
import android.view.Menu;
import android.widget.ArrayAdapter;

public class List extends ListActivity {
private String[] listItems = new String[] { "Apple", "Android", "Symbian", "Window" };
private ArrayAdapter< String> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

adapter = new ArrayAdapter(this, R.layout.list, R.id.text1, listItems);
setListAdapter(adapter);
}


}

List Items are Displayed in Text View . So create new XML file in res Layout Folder
and simple copy the XML code.

<br /> <!--xml version="1.0" encoding="utf-8"?--><br /> <textview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dip"/><br />

The Following are the Main layout "activity_list" file
<br /> <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:orientation="vertical"><br /> <listview android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent"/><br /> <textview android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="no_reminders" /><br /> </RelativeLayout><br />

Post a Comment

0 Comments