一个活动中的Actionbar和ListActivity [英] Actionbar and ListActivity in one Activity

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

问题描述

我有一个程序,该程序显示SDCARD上目录中的文件列表,当用户单击文件时,它会打开PDF.例如,一个活动将显示一个文件夹的内容.

I have a program which shows lists of files in directories on the SDCARD and when the user clicks on a file it opens the PDF up. For instance one activity will display the contents of one folder.

我一直想添加ActionBar进行导航,并且可以让ActionBar在其自己的活动中工作,而ListActivity在其自己的活动中工作,但是我无法让它们一起工作.

I have been wanting to add the ActionBar for navigation and can get the ActionBar to work in its own activity and my ListActivity to work in its own activity, however I cannot get them to work together.

我不确定如何将两者结合起来,最终得到一个活动,该活动在一个活动中显示操作栏和文件列表?

I am not sure how to combine the two so that I end up with one activity that displays the action bar and the file list in the one Activity?

动作栏活动以

public class SecondActivity extends FragmentActivity implements ActionBar.OnNavigationListener {

显示可点击列表的活动以

The Activity that displays the clickable list starts with

public class MainActivity extends ListActivity {

我的android应用程序编程是非常基础的并且是自学的,所以我可能缺少明显的东西.预先感谢

My android app programming is quite basic and self taught so I am probably missing something obvious. Thanks in advance

推荐答案

我认为您可以将您的类扩展到ListActivity并覆盖方法onCreateOptionsMenu以将操作栏绑定到活动:

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
}

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

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