带有网络视图的列表视图 [英] Listview with webview

查看:22
本文介绍了带有网络视图的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个带有 Webview 的 ListView,但该应用程序没有显示任何内容.这是我的代码:

i'm trying to create a ListView with a Webview inside, but the app shows nothing. Here my Code:

我设置 CustomAdapter 的 MainActivity

The MainActivity where I set the CustomAdapter

    public class Web_in_list1Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView lv = (ListView)findViewById(R.id.listView2);
    ListViewAdapter adapter = new ListViewAdapter(this);

    lv.setAdapter(adapter);

    }
    }

自定义适配器的getView在这里,我获取了 ListView 的布局并获取了 Webview 的 URL

getView of the CustomAdapter Here I get the Layout for the ListView and ste the URL for the Webview

    public View getView(int arg0, View convertView, ViewGroup arg2) {
    // TODO Auto-generated method stub

    LayoutInflater inflater =  context.getLayoutInflater();
    convertView = inflater.inflate(R.layout.listitem, null);

    WebView wv = (WebView)convertView.findViewById(R.id.webview);
    wv.getSettings().setJavaScriptEnabled(true);
            wv.loadUrl("http://www.google.com");

            convertView.setTag(wv);

    return convertView;
}

main.xml

     <?xml version="1.0" encoding="utf-8"?>

     <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:orientation="vertical">

    <ListView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="fill_parent"
            android:id="@+id/listView2"
            android:layout_width="fill_parent"/>
     </LinearLayout>

列表项.xml

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:orientation="vertical">


    <WebView  

            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>

关闭!问题通过滚动视图解决

CLOSED! PROBLEM SOLVED WITH A SCROLLVIEW

推荐答案

我正在尝试创建一个带有 Webview 的 ListView

i'm trying to create a ListView with a Webview inside

你不能把可滚动的东西可靠地放在其他可滚动的东西里面.因此,您不能可靠地:

You cannot reliably put scrollable things inside of other scrollable things. Hence, you cannot reliably:

  • ListView 行中放置一个 WebView
  • ListView 行中放置一个 ScrollView
  • WebView 放入 ScrollView
  • ListView 放入 ScrollView
  • Put a WebView in a ListView row
  • Put a ScrollView in a ListView row
  • Put a WebView in a ScrollView
  • Put a ListView in a ScrollView

此外,WebView 是一个非常重量级的小部件,并没有设计成有大量的副本.请考虑使用 TextView 进行轻量级 HTML 渲染.

Moreover, a WebView is a very heavyweight widget and is not designed to have lots of copies floating around. Please consider using TextView for lightweight HTML rendering.

这篇关于带有网络视图的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆