Reputation: 3
I have a problem with my WebView and I don't know how fix it. Before added the WebView, I had a ListView, now I have only a white screen when I launch the activity. Can you help me to fix it please ?
Here the XML file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ListView
android:id="@+id/lvMods"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
And my Java file :
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class Mods extends Test {
private ListView lvMods;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listemods);
lvMods = (ListView)findViewById(R.id.lvMods);
String[] listeStrings = {"1","2","3","4"};
lvMods.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listeStrings));
lvMods.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
CallFunc(position);
}
private void CallFunc(int position) {
WebView wvpdf = (WebView)findViewById(R.id.webview);
wvpdf.getSettings().setJavaScriptEnabled(true);
switch (position) {
case 0:
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXXXXXXXXXXXXX");
break;
case 1 :
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXXXXXXXXXX");
break;
case 2 :
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXXXXXX");
break;
case 3 :
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXX");
}
}
});
}}
Note : in my manifest I have Internet permissions
Thank you very much
Upvotes: 0
Views: 3999
Reputation: 3050
Don't use fill_parent
to all View
s.. Try using weight instead to manage the proportion of the layout...
Upvotes: 0
Reputation: 53687
Instead of setting layout:height="fill_parent"webview as fillparent make it as layout_height="wrap_content". Because if you do webview as fill parent then you cannot see listview. I have set minimum:height and background color those are not mandatory.
Donot forget to vote my answer. If it is useful for you.
Thanks
Deepak
Please find the following xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:minHeight="60dip"
/>
<ListView
android:id="@+id/lvMods"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
</ListView>
</LinearLayout>
Upvotes: 2