0
回答
怎么向viewpager的一页显示webview?

lz新建了一个viewpager,并加载了3个页面,每个页面加了一个webview,那么怎么实现在mainactivity按下按钮后跳转到这个viewpager,然后在页面中加载网址?源码贴上,求大神,急啊!  

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub


Intent intent=new Intent();
intent.setClass(MainActivity.this, connect.class);
startActivity(intent);

以上是mainactivity中的绑定代码




package com.example.compare;


import java.util.ArrayList;
import java.util.List;


import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;


public class connect extends Activity {
public ViewPager viewPager;
public PagerTitleStrip pagerTitleStrip;
public List<View> viewlist;
public List<String> titlelist;


public WebView webView;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.afterconnect);
viewPager=(ViewPager)this.findViewById(R.id.viewpager1);
pagerTitleStrip=(PagerTitleStrip)this.findViewById(R.id.titlestrip1);

View view1=LayoutInflater.from(connect.this).inflate(R.layout.tab1, null);
View view2=LayoutInflater.from(connect.this).inflate(R.layout.tab2, null);
View view3=LayoutInflater.from(connect.this).inflate(R.layout.tab3, null);

viewlist=new ArrayList<View>();
viewlist.add(view1);
viewlist.add(view2);
viewlist.add(view3);

titlelist=new ArrayList<String>();
titlelist.add("1");
titlelist.add("2");
titlelist.add("3");

viewPager.setAdapter(  myAdapter);
  
}

public PagerAdapter myAdapter=new PagerAdapter(){


@Override
public Object instantiateItem(View container, int position) {
((ViewPager)container).addView(viewlist.get(position));
return viewlist.get(position);

}
@Override
public CharSequence getPageTitle(int position) {
return titlelist.get(position);
};
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0==arg1;
}


@Override
public int getCount() {
// TODO Auto-generated method stub
return viewlist.size();
}
@Override
public void destroyItem(android.view.ViewGroup container, int position, Object object) {
((ViewPager)container).removeView(viewlist.get(position));
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}




}


举报
kaiyuanww
发帖于4年前 0回/499阅
顶部