LinearLayout for ListAdapter : LinearLayout « UI « Android





LinearLayout for ListAdapter

   

package app.test;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Test extends ListActivity {
  private String[] data = {};

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setListAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, data));
  }

  protected void onListItemClick(ListView listView, View v, int position,
      long id) {
    super.onListItemClick(listView, v, position, id);
    setTitle(listView.getItemAtPosition(position).toString());
  }
}



//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
    android:layout_height="wrap_content">
  <ListView android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    <TextView android:id="@id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Empty"/>      
</LinearLayout>

   
    
    
  










Related examples in the same category

1.Adding two controls to LinearLayout
2.Using LinearLayout for Activity
3.Using LinearLayout to layout two RadioGroups
4.Using LinearLayout.LayoutParams
5.Using LinearLayout
6.LinearLayout which uses a combination of wrap_content on itself and match_parent on its children to get every item to be the same width.
7.LinearLayout inside ScrollView
8.Transparent Panel extends LinearLayout
9.Set min height
10.Set padding right
11.Set padding with dpi value
12.Baseline alignment includes a android.widget.LinearLayout within another android.widget.LinearLayout.