列表视图与web视图 [英] Listview with webview

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

问题描述

我想要创建一个web视图里面一个ListView,但应用程序显示什么。 在这里,我的code:

我的设置CustomAdapter的MainActivity

 公共类Web_in_list1Activity延伸活动{
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    ListView的LV =(ListView控件)findViewById(R.id.listView2);
    ListViewAdapter适配器=新ListViewAdapter(本);

    lv.setAdapter(适配器);

    }
    }
 

在CustomAdapter的getView 在这里,我得到的布局的ListView和STE的URL web视图

 公开查看getView(INT为arg0,查看convertView,ViewGroup中ARG2){
    // TODO自动生成方法存根

    LayoutInflater充气= context.getLayoutInflater();
    convertView = inflater.inflate(R.layout.listitem,NULL);

    的WebView WV =(web视图)convertView.findViewById(R.id.webview);
    wv.getSettings()setJavaScriptEnabled(真)。
            wv.loadUrl(http://www.google.com);

            convertView.setTag(WV);

    返回convertView;
}
 

main.xml中

 < XML版本=1.0编码=UTF-8&GT?;

     <的LinearLayout
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:layout_height =FILL_PARENT
        机器人:layout_width =FILL_PARENT
        机器人:方向=垂直>

    <的ListView
            的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:layout_height =FILL_PARENT
            机器人:ID =@ + ID / listView2
            机器人:layout_width =FILL_PARENT/>
     < / LinearLayout中>
 

listitem.xml

 < XML版本=1.0编码=UTF-8&GT?;

    <的LinearLayout
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:layout_height =FILL_PARENT
        机器人:layout_width =FILL_PARENT
        机器人:方向=垂直>


    <的WebView

            机器人:ID =@ + ID / web视图
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>
    < / LinearLayout中>
 

关门了! 问题解决了滚动型

解决方案
  

我想要创建一个web视图一个ListView里面

您不能可靠地把其它滚动里面的东西可滚动的东西。因此,你不能可靠:

  • 将一个的WebView 的ListView
  • 将一个滚动型的ListView
  • 将一个的WebView 滚动型
  • 将一个的ListView 滚动型

此外,的WebView 是一个非常重量级的小部件,而不是设计有大量的拷贝流传的。请考虑使用的TextView 轻量级的HTML渲染。

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

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 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>

listitem.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

解决方案

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:

  • 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

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.

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

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