簡體   English   中英

如何在ExpandableListView中添加WebView?

[英]How To add WebView in ExpandableListView?

如何在可擴展列表視圖中添加Webview? 我需要在expandableListView下添加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>

只需假設每個組的子元素都是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等網絡庫來加載Web內容,而不是簡單地說mWebView.loadUrl(url)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM