Finally figured it all out. Here is the final code extended from
ListActivity.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <TextView
                android:id="@+id/tvHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Hello List Activity"/>
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>

public class HelloListActivity extends ListActivity {
        private TextView tv;
        private TextView tp;
        private ListView lv;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv = (TextView) findViewById(R.id.tvHeader);

        tp = new TextView(this);
        tp.setText("Top of the list");

        getListView().addHeaderView(tp);
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, COUNTRIES));

    }

    @Override
        protected void onListItemClick(ListView l, View v, int position, long
id) {
                // TODO Auto-generated method stub
                super.onListItemClick(l, v, position, id);
                String temp = l.getItemAtPosition(position).toString();
                Toast.makeText(HelloListActivity.this, temp, 
Toast.LENGTH_SHORT).show
();
        }

        static final String[] COUNTRIES = new String[] {
            "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
            "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda",
"Argentina"
        };
}

On Aug 17, 12:55 am, chinchin <nchinn...@googlemail.com> wrote:
> Hello,
> I'm trying to modify the HelloListView example to useaddHeaderViewor
> addFooterView. Unfortunately I am unable to get this working. Is
> anyone able to provide any help?
> Here is my code, thanks in advance.
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>     android:orientation="vertical"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent"
>     >
>         <TextView
>                 android:id="@+id/textDisplay"
>                 android:layout_width="fill_parent"
>                 android:layout_height="wrap_content"
>                 android:text="Hello!"
>         />
> </LinearLayout>
>
> public class HelloListView extends ListActivity {
>         private TextView test;
>
>     /** Called when the activity is first created. */
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>           super.onCreate(savedInstanceState);
>
>           test = (TextView) findViewById(R.id.textDisplay);
>
>           getListView().addHeaderView(test);
>           setListAdapter(new ArrayAdapter<String>(this,
>                   android.R.layout.simple_list_item_1, COUNTRIES));
>           getListView().setTextFilterEnabled(true);
>         }
>
>         static final String[] COUNTRIES = new String[] {
>             "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
>             "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda",
> "Argentina"
>           };
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to