Webview not displaying html - android

My webview in my application does not show up. I went to the interwebs to find an answer, but I found nothing, just tutorials on how to use the control. I am trying to load a html file, but it is not showing.
I added the user permission 'Internet' to my manifest.
Here is my layout:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:visibility="visible" >
<WebView
android:id="#+id/wvInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
</TableLayout>
I have a file, 'filename.html' in my assets folder.
The following code is in the onCreate:
WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
wvinfo.loadUrl("file:///android_asset/filename.html");
When I load the program on my phone, nothing shows up. I also tried to load an url, "http://www.google.com" and still nothing shows. I am stumped. Any ideas?

Try the below code in your layout file
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="#+id/wvInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableLayout>

My guess is that you haven't setContent the layout inside onCreate().
Try like this ...
setContentView(R.layout.webview_layout);

Why are you using a Table Layout for a Web view? Instead use a Linear or Relative Layout.
Try adding this
WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
wvinfo .getSettings().setJavaScriptEnabled(true);
wvinfo.loadUrl("file:///android_asset/filename.html");
Let me know if it works.

Related

iframe is not display correclty in android webview

I am using Webview to display iframe in android. Below is my java code
String html = "<p><blockquote><iframe height=\"740\" src=\"https://docs.google.com/document/d/e/2PACX-1vSCZgt7yvY-9aB3RSvQqhYXE0EZ_Lp7AMTMmxlGfJP04iHBjX4A7dVVrc-b9OBX3kLWp_dLyUvNjhLa/pub?embedded=true\" width=\"100%\"> </iframe></blockquote></p>";
webview.loadData(html, "text/html",null);
below is my xml
<LinearLayout
android:layout_width="match_parent"
android:background="#color/colorWhite"
android:layout_height="match_parent">
<WebView
android:id="#+id/webViewPage"
android:background="#color/colorWhite"
android:layout_width="fill_parent"
android:paddingBottom="53dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
But when we run code its look like below screen
How its show margin or padding from left and right?
How can we resolve this issue?
u should make your WebView heght and width are match_parent
<LinearLayout
android:layout_width="match_parent"
android:background="#color/colorWhite"
android:layout_height="match_parent">
<WebView
android:id="#+id/webViewPage"
android:background="#color/colorWhite"
android:layout_width="match_parent"
android:paddingBottom="53dp"
android:layout_height="match_parent"
/>
</LinearLayout>
You need to change the width=\"100%\" to a value because It will not load correctly.
Just say width=\"100px\" by example and you will see that the borders are gone.

Webview + ListView one overlays the other in Activity

So I'm having this XML File:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/viplounge"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/wview"
android:orientation="vertical"
android:background="#android:color/black"
/>
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/viplist"
android:layout_below="#id/wview"
/>
</RelativeLayout>
Where the WebView is loading Text from my strings.xml, the text is formatted with HTML for a better displaying experience and is quiet long, so it doesn't fit on the display and the WebView is therefore scrollable.
Under the WebView(Text) I'm parsing a XML File with some data from the Internet which is displayed in a ListView.
So my problem is, that I can't get the ListView below my WebView plus I want to manage it like that: When I'm done scrolling in my WebView I want to show the ListView below. So the User has to go down the Text/WebView and then he can read the information from the ListView.
The App is basically describing a location and under the description there should be the list of dates when the location is available and when not. Just to get you an Idea of what I'm doing here.
you can use NestedScrollView
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/viplounge"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/wview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:orientation="vertical" />
<ListView
android:id="#+id/viplist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/wview" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

"linearLayout cannot be resolved or it is not a field" with AdMob instructions by Google for Android

I am trying to find a solution to my problem by an hour and I found some topics with my similar problem, but I don't understand how to resolve.
I was developing an app with Processing for Android and I wanted to try AdMob (just for learning, for now), so I followed instructions all over the net and now I am stuck.
To add ads in the app, I was following Google instructions to add the SDK of Play Service and to add banners, but I am stuck here:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
initPdService();
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pu....83399");
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder()
// .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
// .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
The problem is that it give me "linearLayout cannot be resolved or it is not a field", and I don't know how to resolve. I think that the problem is in findViewById(R.id.linearLayout), since the error is at "linearLayout" and not "LinearLayout".
I am sure that a lot of people find this problem, so I think that is a common problem. I already added import android.widget.LinearLayout;at the top of the sketch, so I don't know what is the problem.
Other infos: it is targeting Android SDK 19, as I know that Play Services want at least API level 13.
EDIT:
Here is my [old] activity_main.xml found is /res/layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<android.support.v7.widget.Space
android:id="#+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginTop="208dp"
android:layout_toRightOf="#+id/adView" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
EDIT 2:
This is my new activity_main.xml, with linearLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<android.support.v7.widget.Space
android:id="#+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginTop="208dp"
android:layout_toRightOf="#+id/adView" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
</RelativeLayout>
You need to set your content view:
setContentView(R.layout.activity_main);
which you have commented out. Do you have an xml file "activity_main.xml" that contains the LinearLayout with an id, linearLayout?
If yout don't have a LinearLayout with the id linearLayout, you need to add one. Otherwise, it's trying to find a view (by id!) that doesn't exist. For example:
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
...
</LinearLayout>
Your issue is that you are using Processing as a library on top of the Android SDK, and it doesn't have access to the layout files, as in Processing you create your screens programatically - it is similar to one big Canvas class for those that are familiar with Android and not Processing.
What the actual compilation error is saying is that the generated R.java file is not finding the compressed resources
I've never tried to add AdMob, but really i think your issue here is that you need to instantiate a LinearLayout programatically, not via XML - as again, you won't have access to that through the PDE.
EDIT:
just noticed that you are using Eclipse (and LibPd !!)... ok, so you can reach a layout
Can you show the code where you are importing Processing into the Activity ?

Where the right place to set layout in android?

I have 2 files in the res.
Activity_main.xml is
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test2.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.test2.MainActivity$PlaceholderFragment" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
I plan to change the layout where I problem in this current layout when I drag and drop all item just overlap on each other how to make a nice form type layout? What adjustment and which file must I adjust?
It sounds like you are using the Eclipse GUI tools to create your layout. I strongly suggest that you read about Android Layouts. If you want, you can edit the XML layout text directly or at the very least this will help you understand the properties you can set for your controls to get the exact look that you want.

Why is my Webview resizing itself?

I'm a noob to android development and my webview resizes itself whenever i try to play video. In order to make the webview play video i had to add the line of code:
youtube.getSettings().setPluginState(PluginState.ON);
In my layout, I have my webview above a listview. However, now when the webview plays video it becomes fullscreen and covers listview. this was not happening before i added the line above. How do I stop my webview from resizing itself? Any help is greatly appreciated?
Here is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/LLvideos" >
<WebView
android:id="#+id/webViewyoutube"
android:layout_width="match_parent"
android:layout_height="350dp" >
</WebView>
<!-- List view -->
<ListView
android:id="#+id/videolist"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#00000000"
android:dividerHeight="0dp" >
</ListView>
Here is my video link
youtube.loadUrl("http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=1858951133001");
Sounds like you are have a scaling issue. Try youtube.setInitialScale(50). This should work.
Try setting the webview layout like this:
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

Categories

Resources