tags:

views:

203

answers:

3

I am trying to use a custom title to include an image button to the title bar. I got a lot of help form this post: http://stackoverflow.com/questions/2569753/android-adding-button-to-the-title-of-the-app, but could not get it work for my ListActivity.

In a nutshell, following is what I have:

  1. I hide the titlebar in the AndroidManifest.xml
  2. The specify a relative layout for the custom title (workorder_list_titlebar.xml)

  3. My Activity Class looks like the following:

    public class WorkOrderListActivity extends ListActivity {
     String[] orders={"WO-12022009", "WO-12302009","WO-02122010", "02152010"};
     @Override
     public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);   
       requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
       this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.workorder_list_titlebar);
       setContentView(R.layout.workorder_list);
       setListAdapter(new ArrayAdapter(this,R.layout.workorder_list, R.id.label,orders));    
            }
    }

When I ran the app, I got AndroidRuntimeException: You cannot combine custom titles with other title features.

Base on the stack trace, the exception was thrown by com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:183), that was triggered by setlistAdapter call.

Does anyone have the same problem with ListActivity? Also once I manage to get this work, how do I attach listeners to the image button for it to do something?

Thanks in advance.

A: 

Try swapping following lines:

setContentView(R.layout.workorder_list);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.workorder_list_titlebar);
alinux
I am having the same issue and this didn't fix the force close.
Macarse
+2  A: 

I had the same issue and I fix it deleting

<item name="android:windowNoTitle">true</item>

from my theme.xml

Macarse
A: 

May be you find this problem when use it in tab,for there already have a title and you can not add a custom title again.

you should add this custom title in the activity which you get the Tab

notenking