Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to load webview in tab view
    primarykey
    data
    text
    <p>I have no idea why my webview is unable to load in my tabhost/tabwidget. For the tabhost/tabwidget, I am using the tutorial that was provided by Android Developer. Also, in my logcat, the warning seems to be at the tab1Activity.java, pointing the warning to "wv.loadDataWithBaseURL("http://lovetherings.livejournal.com/961.html", myString, "text/html", "UTF-8", "about:blank"); " </p> <p>Below are my codes. Can anyone help me? Thanks so much in advance! :D </p> <p>Here is my main.xml </p> <pre><code> &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p> </p> <p>My main activity</p> <pre><code>public class HelloTabWidgetMain extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("tab1").setIndicator("tab1", res.getDrawable(R.drawable.ic_tab_tab1)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, tab2Activity.class); spec = tabHost.newTabSpec("tab2").setIndicator("tab2", res.getDrawable(R.drawable.ic_tab_tab2)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, tab3Activity.class); spec = tabHost.newTabSpec("tab3").setIndicator("tab3", res.getDrawable(R.drawable.ic_tab_tab3)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); } </code></pre> <p>}</p> <p>And my tab activity (where I would want my webview contents to be displayed)</p> <pre><code>public class tab1Activity extends Activity{ WebView wv; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { URL url = new URL("http://lovetherings.livejournal.com/961.html"); // Make the connection URLConnection conn = url.openConnection(); BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); // Read the contents line by line (assume it is text), // storing it all into one string String content =""; String line = reader.readLine(); while (line != null) { content += line + "\n"; line = reader.readLine(); } reader.close(); String myString = content.substring(content.indexOf("&lt;newcollection&gt;")); int start = myString.indexOf("&lt;newcollection&gt;"); if (start &lt; 0) { Log.d(this.toString(), "collection start tag not found"); } else { int end = myString.indexOf("&lt;/newcollection&gt;", start) + 8; if (end &lt; 0) { Log.d(this.toString(), "collection end tag not found"); } else { myString = "&lt;html&gt;&lt;body&gt;" + myString.substring(start, end) + "&lt;/body&gt;&lt;/html&gt;"; } WebView wv = (WebView)findViewById(R.id.webview); wv.loadDataWithBaseURL("http://lovetherings.livejournal.com/961.html", myString, "text/html", "UTF-8", "about:blank"); } } catch (Exception ex) { ex.printStackTrace(); // Display the string in txt_content //TextView txtContent = (TextView)findViewById(R.id.txt_content); //txtContent.setText(myString); } } </code></pre> <p>}</p> <p>Please help me! Thanks in advance! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload