开发者

Custom title bar with ListView

开发者 https://www.devze.com 2023-01-30 03:51 出处:网络
I have a ListView in one of my activities. I also want to have a custom title bar in the same activity. So my onCreate method starts something like

I have a ListView in one of my activities. I also want to have a custom title bar in the same activity. So my onCreate method starts something like

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);    
        setContentView(R.layout.ca开发者_运维百科tegorieslayout); //yup, i am not extending ListActivity, but just Activity
        setCustomTitleBar();
                ...
    }

When i run this, i get the error

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

If i comment out the part where i request the window feature and call the function to set the custom title bar, it works fine. I am not sure how to get through this.

Any help is appreciated, thanks


Your error is not related to custom title. You just need to fix your layout so it has explicit ListView declaration and that ListView shoud have a predefined id of android.R.id.list:

<ListView android:id="@id/android:list" ... />
0

精彩评论

暂无评论...
验证码 换一张
取 消