2016-08-08 89 views
3

我在我的recyclerview中有3種類型的itemview,最後一個是包含完整的webview。當我點擊webview時,這是一個recyclerview行,然後recyclerview滾動。我該如何解決這個問題。recycleview中的webview無法正常工作

這是我的佈局,containts的WebView

<?xml version="1.0" encoding="utf-8"?> 
<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/webView"> 
</WebView> 

適配器:

public class HomePageAdapter extends  RecyclerView.Adapter<RecyclerView.ViewHolder> { 

    private String htmlContent; 
    private ArrayList<Slider> homePageSliders; 
    private ArrayList<HomePageItem> homePageItems; 

    private final int VIEW_SLIDER = 0; 
    private final int VIEW_HOMEPAGEITEM = 1; 
    private final int VIEW_HOMEPAGEHTML = 2; 


    private OnItemClickCallBack<HomePageItem> callBack; 

    public HomePageAdapter(ArrayList<Slider> homePageSliders, ArrayList<HomePageItem> homePageItems, String htmlContent, OnItemClickCallBack<HomePageItem> callBack) 
    { 
     this.homePageSliders = homePageSliders; 
     this.homePageItems = homePageItems; 
     this.htmlContent  = htmlContent; 
     this.callBack  = callBack; 

    } 

    @Override 
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

     if(viewType == VIEW_SLIDER) { 
      return new HomePageSliderHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.row_homepage_slider, parent, false)); 
     } 
     else if(viewType == VIEW_HOMEPAGEITEM) 
     { 
      return new HomePageItemHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.row_homepage_item, parent, false)); 

     } 
     else 
     { 
      return new HomePageHtmlContentHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.row_homepage_html, parent, false)); 
     } 
    } 

    @Override 
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 

     if(holder instanceof HomePageSliderHolder) 
     { 
      HomePageSliderHolder viewHolder = (HomePageSliderHolder) holder; 
      viewHolder.setViewPagerAdapter(this.homePageSliders); 
     } 
     else if(holder instanceof HomePageItemHolder) 
     { 
      HomePageItemHolder viewHolder = (HomePageItemHolder) holder; 

      int newPosition = position -1; 
      final HomePageItem homePageItem = this.homePageItems.get(newPosition); 

      viewHolder.setImagePath(homePageItem); 
      viewHolder.itemView.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        callBack.onItemClick(homePageItem); 
       } 
      }); 
     } 
     else 
     { 
      HomePageHtmlContentHolder viewHolder = (HomePageHtmlContentHolder) holder; 
      viewHolder.setHtml(htmlContent); 
      viewHolder.setWebViewClickListener(); 
     } 
    } 

    @Override 
    public int getItemCount() { 
     return 1 + 1 + homePageItems.size(); 
    } 

    @Override 
    public int getItemViewType(int position) { 

     if(position == 0) 
     { 
      return VIEW_SLIDER; 
     } 
     else if(position < homePageItems.size()) 
     { 
      return VIEW_HOMEPAGEITEM; 
     } 
     else 
     { 
      return VIEW_HOMEPAGEHTML; 
     } 

    } 
} 

網頁視圖點擊收聽:

public void setWebViewClickListener() 
    { 
     this.webView.setWebViewClient(new WebViewClient(){ 

      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       Crashlytics.log(Log.ASSERT, "url : ", url); 
       return true; 
      } 
     }); 
    } 

回答

0

當我研究了HTML響應後來我意識到,有重定向網址中沒有任何主機(例如google://)。然後我通過包含主機來取代它,它的功能就像一個魅力。

相關問題