有什么方法可以在一个 activity 中添加操作栏和列表视图?

Any way to add actionbar and listview in one single activity?

当我打开 activity 时,导航抽屉不会显示。那么有什么方法可以将 listview 和 actionbar 添加到一个 activity 中吗?如果有人能帮助我,我将不胜感激。谢谢

public class Cart extends ListActivity {

ArrayAdapter<String> mAdapter;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cart);


    String[] items = new String[2];
    items[0] = "";


    mAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            android.R.id.text1,
            new ArrayList<String>(Arrays.asList(items)));
    setListAdapter(mAdapter);

    ListView listView = getListView();

    SwipeDismissListViewTouchListener touchListener =
            new SwipeDismissListViewTouchListener(
                    listView,
                    new SwipeDismissListViewTouchListener.DismissCallbacks() {
                        @Override
                        public boolean canDismiss(int position) {
                            return true;
                        }

                        @Override
                        public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                            for (int position : reverseSortedPositions) {
                                mAdapter.remove(mAdapter.getItem(position));
                            }
                            mAdapter.notifyDataSetChanged();
                        }
                    });
    listView.setOnTouchListener(touchListener);// ListView scrolling,

}

只需将 ListView 放入 ActionBarActivity

public class someActivity extends ActionBarActivity {

    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_some);

        listView = (ListView) findViewById(R.id.listView);
        YourAdapter listAdapter = new YourAdapter();
        listView.setAdapter(listAdapter);
    }
}

Xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
    android:id="@+id/listView"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>

</LinearLayout>

谢谢乔!!我只需要登录并给这个答案竖起大拇指。解决了我的问题。比我最近几天查到的任何答案都好:)

这是我如何解决它的一段代码

使用 AppCompatActivity 作为 ActionBarActivity 似乎已被弃用。

public class SelectActivity extends AppCompatActivity /*ListActivity*/ implements OnClickListener {

ListView listView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select_clothes);

    listView = (ListView) findViewById(R.id.listView);

    mList = getListData();
    MyAdapter listAdapter = new MyAdapter(this, R.layout.row, mList);
    listView.setAdapter(listAdapter);
}