You can do as shown below, or add a text view as a title to your list
Quote from the docs
ListActivity (similar to ListFragment) has a default layout, which consists of a single full-screen list in the center of the screen. However, if you wish, you can customize the screen layout by setting your own view layout using setContentView()
in the onCreate () object . To do this, your own view MUST contain a
. To do this, your own view MUST contain a
ListView` with id "@android: id / list" (or list if it is in code)
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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <fragment android:name="com.example.listfragment.MyFragment" android:id="@+id/frag" android:layout_above="@+id/button1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </RelativeLayout>
MyFragment.java
public class MyFragment extends ListFragment { String names[] ={"A","B","C"}; @Override public void onActivityCreated(Bundle savedInstanceState) {
list_frag.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="TextView" /> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" > </ListView> </RelativeLayout>
snap shot

Edit: if you want the text to be viewed
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="19dp" android:text="TextView" /> </RelativeLayout>
Before calling setListAdapter
View view = inflater.inflate(R.layout.text, null); TextView textinlfated = (TextView) view.findViewById(R.id.textView1); ListView lv = getListView(); textinlfated.setText("TextView scrolls"); lv.addHeaderView(view);
source share