Trying to add WebView to modified tab Layout fr developer.an

Put your problem here if it does not fit any of the other categories.

Trying to add WebView to modified tab Layout fr developer.an

Postby le4rner » Wed Apr 06, 2011 9:16 pm

Hello all,

Thanks to anyone responding. I have been plugging away at this app for about 2 weeks now. I have done a few app tutorials now and I am learning the basic flow of the code in an app on android. Well I think I am :?

I was able to get the tab layout to run fine. I want to add a WebView object to one of the tabs. I know I have gotten something wrong here. I commented out all the WebView based code from my tab activity and went back to a TextView and my app is still crashing. I know this is a noob post, I did do searches here and in google. Thats how I found this place actually. The closest thing I found was this post

other-coding-problems-f5/webview-problem-t51777.html It came close I think, but as I said, Even removing all webview code my app breaks. I am slamming my head against my monitor here and I think I just need another set of eye to point out what I am missing.

I will post my code hoping I am not too presumptuous.

AndroidManifest.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.UmmsEncyclopedia"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
   
    <uses-permission android:name="android.permission.INTERNET" />
   
    <application android:icon="@drawable/icon" android:label="@string/app_name">
       <activity android:name=".UmmsEncyclopedia"
                 android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="HomeActivity"></activity>
        <activity android:name="SocialActivity"></activity>
        <activity android:name="BookmarkActivity"></activity>
    </application>
</manifest>


main.java(base class)
Code: Select all
package com.UmmsEncyclopedia;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class main 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;              //Reusable 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, HomeActivity.class);
       // Initialize a TabSpec for each tab and add it to the TabHost
       spec = tabHost.newTabSpec("home").setIndicator("Home",
                         res.getDrawable(R.drawable.ic_tab_home))
                         .setContent(intent);
       tabHost.addTab(spec);
       // Do the same for the other tabs
       intent = new Intent().setClass(this, SocialActivity.class);
       spec = tabHost.newTabSpec("social").setIndicator("Albums",
                         res.getDrawable(R.drawable.ic_tab_social))
                         .setContent(intent);
       tabHost.addTab(spec);
       intent = new Intent().setClass(this, BookmarkActivity.class);
       spec = tabHost.newTabSpec("bookmark").setIndicator("Songs",
                         res.getDrawable(R.drawable.ic_tab_bookmark))
                         .setContent(intent);
       tabHost.addTab(spec);
       tabHost.setCurrentTab(0);
    }
}


HomeActivity.java(The tab/class I think I am having problems with)
Code: Select all
package com.UmmsEncyclopedia;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class HomeActivity extends Activity{
   WebView webview = new WebView(this);
    protected void onCreate(Bundle savedInstanceState) {
      webview.setWebViewClient(new HelloWebViewClient());
        super.onCreate(savedInstanceState);
       

       // webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        setContentView(webview);
        webview.loadUrl("http://www.umm.edu/ency/index_android.htm");
    }
   
   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
       if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
           webview.goBack();
           return true;
       }
       return super.onKeyDown(keyCode, event);
   }
   
   private class HelloWebViewClient extends WebViewClient {
       @Override
       public boolean shouldOverrideUrlLoading(WebView view, String url) {
           view.loadUrl(url);
           return true;
       }
   }
}


/layout/main.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
       <TabWidget
           android:id="@android:id/tabs"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content" />
      <TextView 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/hello"/>
      <FrameLayout
           android:id="@android:id/tabcontent"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:padding="5dp" />
   </LinearLayout>
</TabHost>


Social Tab(Both of the other tab activity classes are pretty simple only the setText() call is different)
Code: Select all
package com.UmmsEncyclopedia;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class SocialActivity extends Activity{
   /**
     * Called when the activity is first created.  Loads a URL into the webView object.
     * @author    rvance@umm.edu
     * @since   3/29/2011
     * @param   Bundle
     * @param   savedInstanceState
     * @return   void
     */
   @Override
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);
        TextView textview = new TextView(this);
        textview.setText("This is the Social tab");
        setContentView(textview);
    }
}


I know this is a lot of code and not sure I should have posted it all, but I know you can not help with code unless you can see it. I think the problem is in HomeActivity.java
User avatar
le4rner
Freshman
Freshman
 
Posts: 3
Joined: Wed Apr 06, 2011 8:44 pm
Location: Maryland, USA

Top

Re: Trying to add WebView to modified tab Layout fr develope

Postby le4rner » Wed Apr 06, 2011 9:47 pm

I just got it working. I downloaded the code from other-coding-problems-f5/webview-problem-t51777.html and noticed I did not edit my code to reflect the CustomWebView.java class that was in the solution for that issue. After doing so and editing my HomeActivity.java file to also match the Google.java file my code now runs. Oh happy day.
User avatar
le4rner
Freshman
Freshman
 
Posts: 3
Joined: Wed Apr 06, 2011 8:44 pm
Location: Maryland, USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 17 guests