How to get supportactionbar when my class extends ExpandableListActivity

坚强是说给别人听的谎言 提交于 2019-12-24 07:29:39

问题


I have a class which extends ExpandableListActivity to display my data as explandable list view, now my app supporting older version till API 7 how to add ActionBar using getSupportActionBar() to this class...Please help me out

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());
    }

}

now suggest me to how to achieve it.


回答1:


Looking at the ExpandableListActivity source code, it seems like it would be easy to duplicate the same functionality in your own class and have it extend ActionBarActivity as its base class.




回答2:


I would suggest you to use the ActionBarActivity. There you have the method getSupportActionBar.

To show your ExpandableList you can add a ListFragment from the support-v4 lib. There is a method called setListAdapter() where you can add a ExpandableListAdapter.

Here is an example.



来源:https://stackoverflow.com/questions/22007024/how-to-get-supportactionbar-when-my-class-extends-expandablelistactivity

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