0

I'm working on an android-app, and I want that the Webview shows up if the Javascript was applied. But now the WebView is only shown after I pull out the Menu.

MainActivity.java http://pastebin.com/Kj4Nbqs9

WebViewFragment.java http://pastebin.com/0kPSub3c

activity_main.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<!-- The main content view -->

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<!-- The navigation drawer -->

<ListView
    android:id="@+id/drawer_list"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

fragment_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>
  • Take a look at this question: http://stackoverflow.com/questions/7661033/android-webview-call-activity-methods-form-javascript-interface. You can set an Interface to get notified by the javascript script. And the you show the WebView based on Visibility. – Wakim Jul 13 '14 at 19:24
  • It should actually work, but I get one error: **The method runOnUiThread(new Runnable(){}) is undefined for the type WebViewFragment.JsObject** http://pastebin.com/GWjMxLMR – Denis Ahmetovic Jul 13 '14 at 21:39
  • I dont think you need to call runOnUiThread, i never worked with WebView but i think its already running on Main Thread. Can you check on debug or comparing the Looper (Looper.myLooper() vs Looper.getMainLooper()) – Wakim Jul 13 '14 at 21:44
  • Now the app force closes.. do you have an idea what i can do? the code is in the post above – Denis Ahmetovic Jul 13 '14 at 22:12
  • You created an JsObject with empty constructor. So there is the Views are null, and on `setVisible` method you access then. Can you post the exception stacktrace? And include the current code and log on the question. – Wakim Jul 13 '14 at 22:17
  • The code doesn't show correctly, so i uploaded it at pastbin: http://pastebin.com/BEFRS2YZ – Denis Ahmetovic Jul 13 '14 at 22:33
  • What error happened? Another thing, place the `webView.setVisibility(...);` before `new Runnable`, you don`t need the Runnable anymore. – Wakim Jul 13 '14 at 22:37
  • Now I edited it, so I don't get an error, but now the webView doesn't get visible again. http://pastebin.com/emXshRQt – Denis Ahmetovic Jul 13 '14 at 23:06
  • Post your layout. Are you using FrameLayout? I always have problem with Visibility in FrameLayout. – Wakim Jul 13 '14 at 23:15
  • I'm using LinearLayout http://pastebin.com/iRGBnJYX – Denis Ahmetovic Jul 13 '14 at 23:19
  • There is something wrong with your code. I'll post an anwser. – Wakim Jul 13 '14 at 23:26
  • It looks like your other answer got deleted... I've actualized the question with the whole code, maybe you can take a look and figure out why the webView doesn't show up again. – Denis Ahmetovic Jul 14 '14 at 11:07
  • It works now, the only problem is that the webview only shows up if I pull out the navigation drawer... – Denis Ahmetovic Jul 14 '14 at 22:32

0 Answers0