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 { @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
source share