[英]Extends in Android using listview and navigation drawer
我有一个带有列表视图的活动,因此我在MainActivity中的extends
是这样的ListActivity
:
public class MainActivity extends ListActivity{
我想实现新的导航抽屉,但是我看到扩展是这样的:
public class MainActivity extends ActionBarActivity {
我该如何解决? 我可以将导航抽屉用于listview活动吗?
像这样
<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);
}
}
是的,可以在不扩展ListActivity
的情况下实现列表。 看看这篇文章。 它显示了没有ListActivity
的列表ListActivity
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.