0

我如何在可擴展列表視圖中添加webview? 我需要expandableListView如何在ExpandableListView中添加WebView?

任何教程下添加HTML文件(可以使用的WebView做)?我該怎麼做?

有沒有其他方法可以做同樣的事情?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="91dp" 
android:descendantFocusability="blocksDescendants" 
android:background="#ffffff"> 
<ImageView 
android:layout_width="30dp" 
android:layout_height="91dp" 
android:id="@+id/sth_cell_img_correct" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:src="@drawable/icon_checked" /> <WebView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clickable="false" 
android:id="@+id/sth_web_view" /> 
</RelativeLayout> 
+0

希望能有一個'單WebView'可擴展列表視圖的孩子? – makata

+0

@makata是的沒錯! –

+1

如果您熟悉基本的BaseExpandableListAdapter和WebView,這應該不難。你有沒有了解基本的ExpandableList,這樣我可以給你一個片段? – makata

回答

1

假設每個組的子元素都是a list of size equal to 1。所以,除了getChildView()getChildrenCount()之外,適配器的其他部分應如往常一樣。另外,您可以使用與組和孩子相同的對象類型。

@Override 
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View rowView, ViewGroup parent) { 
     //String url = mList.get(groupPosition).getChildList().get(childPosition); 
     String url = mList.get(groupPosition).getUrl(); 

     if (rowView == null) { 
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      rowView = inflater.inflate(R.layout.fermata_adapter_body, null); 
      mWebView = (WebView) rowView.findViewById(R.id....); 
      ... 
     } 
     mWebView.loadUrl(url); 
     return rowView; 
    } 

    @Override 
    public int getGroupCount() { 
     return mList.size(); 
    } 

    @Override 
    public int getChildrenCount(int groupPosition) { 
     return 1;//every group has 1 child 
    } 
    @Override 
    public Object getChild(int groupPosition, int childPosition) { 
     return mList.get(groupPosition);//or mList.get(groupPosition).getUrl(); 
    } 
    @Override 
    public Object getGroup(int groupPosition) { 
     return mList.get(groupPosition); 
    } 

爲了更好的可用性,您可能需要使用網絡庫像Volley加載網頁內容,而不是簡單地說mWebView.loadUrl(url)

相關問題