怎么绑定ViewPager中各页面中的元素
如何绑定ViewPager中各页面中的元素?
以上代码能成功初始化并调入ViewPager。其中第一个页面绑定了lay1.xml,内容如下:
请问如何在代码中绑定lay1.xml中id名为webview的元素呢?谢谢!
------解决方案--------------------
楼主的意是获取webView对象?
------解决方案--------------------
WebView wbv = (WebView)lay1.findviewById();
------解决方案--------------------
在pageadapter里面
public Object instantiateItem(View container, int position) {
((ViewPager) container).addView(listviews.get(position));
//这个container;
container.findViewById();
}
private void InitViewPager() {
viewPager = (ViewPager) findViewById(R.id.vPager);
listViews = new ArrayList<View>();
LayoutInflater layoutInflater = getLayoutInflater();
listViews.add(layoutInflater.inflate(R.layout.lay1, null));
listViews.add(layoutInflater.inflate(R.layout.lay2, null));
listViews.add(layoutInflater.inflate(R.layout.lay3, null));
viewPager.setAdapter(new MyPagerAdapter(listViews));
viewPager.setCurrentItem(0);
//省略部分代码。。
}
以上代码能成功初始化并调入ViewPager。其中第一个页面绑定了lay1.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
请问如何在代码中绑定lay1.xml中id名为webview的元素呢?谢谢!
------解决方案--------------------
楼主的意是获取webView对象?
------解决方案--------------------
WebView wbv = (WebView)lay1.findviewById();
------解决方案--------------------
在pageadapter里面
public Object instantiateItem(View container, int position) {
((ViewPager) container).addView(listviews.get(position));
//这个container;
container.findViewById();
}