JasonYun
JasonYun

Reputation: 999

Custom title bar with ListView

I have a Activity Extend ListActivity I want add a LinearLayout or RelativeLayout on top of the list like a action title But when I add in XML List not Display,Why?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TextView android:text="1111" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView1"/>  
</RelativeLayout>
    <ListView android:id="@id/android:list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1" 
        android:drawSelectorOnTop="false" android:padding="4dip" />
    <TextView android:id="@id/android:empty" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="No_data" />
</LinearLayout>

Upvotes: 0

Views: 4234

Answers (4)

yingted
yingted

Reputation: 10554

I was getting the same problem, where nothing showed up. The problem for me was that Android wasn't re-inflating resource properly. Adding the second line here fixed it for me:

final boolean useCustomTitle=requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().getDecorView();//required to make title show up
if(useCustomTitle)
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.my_custom_title);

The second line returns a view, but I don't need it. However, the code will not work without it. You can find the Android source code online if you need to find workarounds. The private TextView mTitleView still isn't updated, so you can either override setTitle or use reflection.

Upvotes: 0

adamp
adamp

Reputation: 28932

Your RelativeLayout above the list has a height of fill_parent and leaves no space left for the list below it. Try setting a different value for layout_height on the RelativeLayout, either a constant height in dips or wrap_content.

You also want orientation="vertical" on your root LinearLayout.

Upvotes: 1

Manish Khot
Manish Khot

Reputation: 3037

You have extended ListActivity. You need to extend just a normal Activity and use a ListView instead of ListActivity.

Refer the link here

Here is the text that you need

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)

Upvotes: 0

Will Tate
Will Tate

Reputation: 33509

Jason,

Google has provided a good example of what you call an "action title" here: http://code.google.com/p/iosched/

Full source code is provided.

Good luck.

Upvotes: 0

Related Questions