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

2019-10-19 09:42发布

我有延伸类ExpandableListActivity显示我的数据explandable列表视图,现在我的应用程序支持旧版本,直到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());
    }

}

现在建议我如何去实现它。

Answer 1:

纵观ExpandableListActivity源代码 ,现在看来似乎会很容易在自己的类来复制相同的功能,并把它扩展ActionBarActivity作为它的基类。



Answer 2:

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

为了显示你的ExpandableList你可以添加一个ListFragment从支持-V4库。 有一个名为方法setListAdapter()您可以添加一个ExpandableListAdapter

下面是一个例子。



文章来源: How to get supportactionbar when my class extends ExpandableListActivity