Issue
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
Solution
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 aListView
row - Put a
ScrollView
in aListView
row - Put a
WebView
in aScrollView
- Put a
ListView
in aScrollView
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.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.