2015-08-27 125 views
-1

我想在我的片段佈局的列表視圖的末尾添加webview。在Android的ListView的末尾添加Webview

這是我的片段佈局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <TextView 
     android:id="@+id/txtTheQueue" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/txt_the_queue" 
     android:textStyle="bold" /> 

    <ListView 
     android:id="@+id/list_queue" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/txtTheQueue" /> 

    <WebView 
     android:id="@+id/webViewQueue" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/list_queue" />  
</RelativeLayout> 

我試圖將webview添加到listview的頁腳。 但是得到這個例外:

java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams 

幫助我。

+0

請發表您的代碼 –

+0

@IntelliJ阿米亞·:我已經說過,我amgetting ClassCastException異常.. – AndiGeeky

回答

0

已解決。

只需添加您的WebView到相對佈局和該佈局添加到列表視圖中的腳註。 我得到這個錯誤,因爲listview和scrollview的layout-params是不同的,而不是在android中的同一棵樹。

這裏是代碼:

WebView lWebView = new WebView(getActivity()); 
lWebView.loadUrl("file:///android_asset/queue.html"); 
RelativeLayout relativeLayout = new RelativeLayout(getActivity()); 
relativeLayout.addView(lWebView); 
listQueue.addFooterView(relativeLayout); 
+0

其顯而易見的錯誤,你必須使用相對佈局,你有算起來你自己。 – Pankaj