80,351
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/page2_list"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:background="#EDEDED"
></ListView>
</LinearLayout>
private void InitViewPager() {
viewPager=(ViewPager) findViewById(R.id.vPager);
views=new ArrayList<View>();
LayoutInflater inflater=getLayoutInflater();
view1=inflater.inflate(R.layout.pager1, null);
listView = (ListView) inflater.inflate(R.layout.pager2, null).findViewById(R.id.page2_list);
view3=inflater.inflate(R.layout.pager3, null);
//这一部分以后可以通过json或者xml解析来得到。数据库中新建一张课程表,然后通过servlet查询,返回json格式数据。
ArrayList<HashMap<String, String>> alist = new ArrayList<HashMap<String,String>>();
String[] lessons = new String[]{"瑜伽", "肚皮舞", "爵士"};
String[] time = new String[]{"17:30", "18:20", "19:30"};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < lessons.length; j++) {
HashMap<String , String> map = new HashMap<String, String>();
map.put("lesson", lessons[j]);
map.put("time", time[j]);
alist.add(map);
}
}
SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, alist, R.layout.pager2_list_item, new String[]{"lesson", "time"}, new int[]{R.id.page2_list_text1, R.id.pager2_list_text2});
listView.setAdapter(simpleAdapter);
views.add(view1);
views.add(listView);
views.add(view3);
viewPager.setAdapter(new MyViewPagerAdapter(views));
viewPager.setCurrentItem(0);
viewPager.setOnPageChangeListener(new MyOnPageChangeListener());
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/page2_list"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:background="#EDEDED"
></ListView>
<include layout="@layout/pager2_foot"/>
</LinearLayout>
[/quote]
将LinearLayout 改为RelativeLayout[/quote]
除此以外,我还需要在MainActivity中做怎样的修改,现在,我viewpager中第二页直接使用的是ListView,代码如上,该如何修改?谢谢指导。<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/page2_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EDEDED" >
</ListView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/page2_list"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:background="#EDEDED"
></ListView>
<include layout="@layout/pager2_foot"/>
</LinearLayout>
[/quote]
将LinearLayout 改为RelativeLayout<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/page2_list"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:background="#EDEDED"
></ListView>
<include layout="@layout/pager2_foot"/>
</LinearLayout>