结合ListActivity和ActionBarActivity [英] Combining ListActivity and ActionBarActivity

查看:274
本文介绍了结合ListActivity和ActionBarActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建设最少10 SDK ,所以我必须使用 Android的支持-V7-appcompat 库来实现动作条。我已经安装了动作条,但我想现在添加 ListActivity ,然而,这需要延长我的阶级和Java没有按'T有多个继承。我该怎么办?

 公共类MainActivity扩展ActionBarActivity {

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气操作栏中使用的菜单项
    MenuInflater充气= getMenuInflater();
    getSupportActionBar()的setIcon(R.drawable.ic_action_search)。
    getSupportActionBar()setDisplayShowHomeEnabled(假)。
    getSupportActionBar()setDisplayShowTitleEnabled(假)。
    inflater.inflate(R.menu.main_activity_actions,菜单);
    返回super.onCreateOptionsMenu(菜单);
   }

 }
 

解决方案

ListActivity还没有被移植到AppCompat。可能是因为你应该考虑'德precated',而是使用一个ListFragment。

片段将与ActionBarActivity工作,只要确保他们是从支持库中的片段。

必须通过有关片段这个的链接。

有关你的使用情况,我也只是定义了片段XML。

I am currently building for a minimum SDK of 10, so I have to use the android-support-v7-appcompat library to implement ActionBar. I have setup the ActionBar, but I want to now add a ListActivity, however this requires extending my class and Java doesn't have multiple inheritance. What should I do?

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    getSupportActionBar().setIcon(R.drawable.ic_action_search);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
   }

 }

解决方案

ListActivity hasn't been ported to AppCompat. Probably because you should consider it 'deprecated', and instead use a ListFragment.

Fragments will work with a ActionBarActivity, just make sure they are fragments from the support library.

Have a read through this link about fragments.

For your use case, I would just define the fragment in xml.

这篇关于结合ListActivity和ActionBarActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆