Web View List

I am trying to create a ListView with a Webview inside, but the application does not show anything. Here is my code:

MainActivity where I install 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 for CustomAdapter Here I get Layout for ListView and ste URL for 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! BROWSE PROBLEM

+3
source share
2 answers

I am trying to create a ListView with a Webview inside

You cannot reliably place scrollable items in other scrollable items. Therefore, you cannot reliably:

  • Put a WebView in the ListView line
  • Put a ScrollView in ListView line
  • Put a WebView in ScrollView
  • Put a ListView in a ScrollView

In addition, a WebView is a very heavy widget and is not intended for a large number of copies floating around. Please consider using TextView to facilitate HTML rendering.

+19
source

Try this code, it worked for me.

 public View getView(final int position, View view, ViewGroup parent) { String Vurl = "your URL"; ViewHolder holder; mHandler = new Handler(); if (view == null) { holder = new ViewHolder(); view = mInflater.inflate(R.layout.listitem, null); holder.browser = (WebView) view.findViewById(R.id.webview); view.setTag(holder); } else holder = (ViewHolder) view.getTag(); holder.browser.getSettings().setJavaScriptEnabled(true); holder.browser.getSettings().setPluginState(WebSettings.PluginState.ON); holder.browser.loadUrl(Vurl); holder.browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); return view; } class ViewHolder { WebView browser; } } 
0
source

Source: https://habr.com/ru/post/979572/


All Articles