Открыть браузер на веб-странице Android-приложение

Пытаясь понять Java и Android, нужна помощь в простой задаче открытия пользовательского браузера после нажатия кнопки.

Я делал обучающие программы в течение последних двух дней, хотя могло бы помочь, если бы я просто попробовал это и получил обратную связь. заранее спасибо за любую помощь.

main.xml:

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bgimage2"> 
    >

<Button
android:id="@+id/goButton"
android:layout_width="150px"
android:layout_height="wrap_content"
android:text="@string/start"
android:layout_x="80px"
android:layout_y="21px"
>
</AbsoluteLayout>

GetURL.java:

package com.patriotsar;

import android.app.Activity;
import android.content.Intent;
import android.view.View.OnClickListener;

String url = "http://www.yahoo.com";
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(url);
i.setData(u);


public class patriosar extends Activity {

     private Button goButton;

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


        goButton.setOnClickListener(new OnClickListener() {         
            @Override
            public void onClick(View v){
                try {
                      // Start the activity
                      startActivity(i);
                    } catch (ActivityNotFoundException e) {
                      // Raise on activity not found
                      Toast toast = Toast.makeText(context, "Browser not found.", Toast.LENGTH_SHORT);
                    }
                  } 
        });

    }
}
5
задан Denoteone 29 May 2011 в 07:40
поделиться