当我的类扩展ExpandableListActivity时如何获得supportactionbar

时间:2014-02-25 07:07:21

标签: android android-actionbar android-support-library android-actionbar-compat

我有一个扩展ExpandableListActivity的类来显示我的数据作为可解释列表视图,现在我的应用支持旧版本,直到API 7如何使用ActionBar向此类添加getSupportActionBar()。 ..请帮帮我

public class Facts extends ExpandableListActivity {


public void onCreate(Bundle savedInstanceState) {

    try{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.facts);

        SimpleExpandableListAdapter expListAdapter =
                new SimpleExpandableListAdapter(
                        this,
                        createGroupList(),              // Creating group List.
                        R.layout.facts_grouprow,                // Group item layout XML.
                        new String[] { "questions" },   // the key of group item.
                        new int[] { R.id.row_name },    // ID of each group item.-Data under the key goes into this TextView.
                        createChildList(),              // childData describes second-level entries.
                        R.layout.facts_childrow,                // Layout for sub-level entries(second level).
                        new String[] {"answers"},       // Keys in childData maps to display.
                        new int[] { R.id.grp_child}     // Data under the keys above go into these TextViews.
                        );
        setListAdapter(expListAdapter);     // setting the adapter in the list

    }catch(Exception e){
        System.out.println("Errrr +++ " + e.getMessage());
    }

}

现在建议我如何实现它。

2 个答案:

答案 0 :(得分:2)

查看ExpandableListActivity source code,似乎很容易在您自己的类中复制相同的功能并将其扩展为ActionBarActivity作为其基类。

答案 1 :(得分:1)

我建议你使用ActionBarActivity。你有方法getSupportActionBar

要显示您的ExpandableList,您可以从support-v4 lib添加ListFragment。 有一种名为setListAdapter()的方法,您可以在其中添加ExpandableListAdapter

Here is an example.