1

我有一个带有列表视图的活动,所以我extends的 MainActivity 是ListActivity这样的:

public class MainActivity extends ListActivity{

我想实现新的导航抽屉,但我看到扩展是这样的:

public class MainActivity extends ActionBarActivity {

我该如何解决?我可以将导航抽屉与列表视图活动一起使用吗?

4

2 回答 2

2

像这样的东西

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fastScrollEnabled="true"
                />

    <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:cacheColorHint="#00000000"
            android:choiceMode="singleChoice"
            android:divider="@drawable/menu_list_divider"
            android:background="@color/very_dark_gray"/>
</android.support.v4.widget.DrawerLayout>

活动

public class YourActivity extends ActionBarActivity{

        private ListView list;
        private ArrayAdapter adapter;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
             setContentView(R.layout.your_view);
            list = (ListView) findViewById(R.id.list);
            adapter = new ArrayAdapter...
            list.setAdapter(adapter);
        }    

    }
于 2013-10-25T09:51:42.427 回答
0

是的,可以在不扩展ListActivity. 看看这篇文章。它显示了一个不带ListActivity.

于 2013-10-25T09:16:56.227 回答