Android app in eclipse

Posted by Colin on Stack Overflow See other posts from Stack Overflow or by Colin
Published on 2011-01-10T21:40:09Z Indexed on 2011/01/10 21:54 UTC
Read the original article Hit count: 415

Filed under:
|
|

Hello everybody,

i've searched for days but cant find an answer, perhaps you guys can help.

I'm creating an android app in eclipse, it all works just one thing is bugging me.

this is my main.java:

    package com.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class Main extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

     // Add Click listeners for all buttons
        View firstButton = findViewById(R.id.btn_rassen);
        firstButton.setOnClickListener(this);
        View secondButton = findViewById(R.id.button2);
        secondButton.setOnClickListener(this);
    }

    // Process the button click events
 @Override
 public void onClick(View v) {
  switch(v.getId()){
   case R.id.btn_rassen:
    Intent j = new Intent(this, Webscreen.class);
       j.putExtra(com.test.Webscreen.URL, 
         "http://www.google.com/");

       startActivity(j);

   break; 

   case R.id.button2:
    Intent k = new Intent(this, Webscreen.class);
       k.putExtra(com.test.Webscreen.URL, 
         "http://notworkingurltotest.com");
       startActivity(k);
   break;

  }  
 }
}

now when it calls the webview.java the page called shows up but not the buttons i created in the layout xml page. does anybody have any idea why this is?

your help is much appreciated!

ohw this is my webscreen.java

package com.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class Webscreen extends Activity {

    public static final String URL = "";
    private static final String TAG = "WebscreenClass";
    private WebView webview;
    private ProgressDialog progressDialog;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.webscreen);

        this.getIntent().getExtras(); 
        this.webview = (WebView) findViewById(R.string.webview);


        String turl = getIntent().getStringExtra(URL);
        Log.i(TAG, " URL = "+turl);

    WebView webview = new WebView(this);
    setContentView(webview);


        final Activity activity = this;     

        webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {              
                view.loadUrl(url);
                return true;
            }


            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                    progressDialog = new ProgressDialog(activity);
                    progressDialog.setMessage("Bezig met laden...");
                    progressDialog.show();

                }
            }

            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;


                }
            }


            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {



                Intent myIntent = new Intent();
                myIntent.setClassName("com.test", "com.test.Main");
                startActivity(myIntent); 

                Toast.makeText(activity, "Laden van onderdeel mislukt, probeer het later nog eens! ", Toast.LENGTH_LONG).show();

                progressDialog.show();
            }

            });




        webview.loadUrl(turl);

    }
}

webscreen.xml layout:

<?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">

  <!-- <1> -->
  <LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="wrap_content">

    <EditText android:id="@+id/url" android:layout_height="wrap_content"
      android:layout_width="wrap_content" android:lines="1"
      android:layout_weight="1.0" android:hint="http://"
      android:visibility="visible" />

    <Button android:id="@+id/go_button" android:layout_height="wrap_content"
      android:layout_width="wrap_content" android:text="go_button" />

  </LinearLayout>

  <!-- <2> -->
  <WebView
        android:id="@string/webview"
        android:layout_width="fill_parent" 
        android:layout_height="0dip"

        />
</LinearLayout>

© Stack Overflow or respective owner

Related posts about android

Related posts about eclipse