Actionbar and ListActivity in one Activity

杀马特。学长 韩版系。学妹 提交于 2019-12-06 12:24:40

I think you can extend your class to ListActivity and override method onCreateOptionsMenu to bind your action bar to the activity:

public class MainActivity extends ListActivity {
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.your_action_bar_name_here, menu);

        return (super.onCreateOptionsMenu(menu));
    }

    // your other methods
}
Nebu

I have posted an alternative solution that separates the concerns of the List and the ActionBar. Makes the code a little tidier IMO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!