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 这样的网络库来加载网络内容,而不是简单地说 mWebView.loadUrl(url)
如何在可扩展列表视图中添加 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 这样的网络库来加载网络内容,而不是简单地说 mWebView.loadUrl(url)