简体   繁体   中英

How to include Action Bar Activity in android Java

I have a an android java class which I am extends another activity , however I would also like to include my ActionbarActivity as well. The code I have below does not seem to do the trick.

public class ExpandableListMainActivity extends ExpandableListActivity   implements ActionBarActivity  

First of all, ActionBarActivity is deprecated.You should use AppCompatActivity instead.

Why was ActionBarActivity deprecated

Secondly, extends ExpandableListActivity implements ActionBarActivity won't work.

Use it like this instead :

public class ExpandableListMainActivity extends AppCompatActivity

For reasons: Implements vs extends: When to use? What's the difference?

  • implements is for implementing an interface

    extends is for extending a class .

So, that's not an interface.

Your Activity should extends AppCompactActivity and then you should declare an ExpandableListView in XML layout for the Activity.

In onCreate of the Activity : setContentView(that_xml_file);

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ExpandableListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ExpandableListView>

</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM