Friday, 13 March 2015

How_to _Link a website ONClick Action for Android apps in Eclipse:

How to  Link  a website ONClick  Action for Android apps in Eclipse:

code for  MainActivity.java  :




package visiscomp.com; //package name
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;



public class MainActivity extends Activity {


    private Button button;



    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        addListenerOnButton();



    }



    public void addListenerOnButton() {



        //Select a specific button to bundle it with the action you want

        button = (Button) findViewById(R.id.button1);



        button.setOnClickListener(new OnClickListener() {



            @Override

            public void onClick(View view) {



              Intent openBrowser =  new Intent(Intent.ACTION_VIEW, Uri.parse("http://vissicomp.com/"));

              startActivity(openBrowser);

            }



        });



    }



}


(2) code for activity_main.xml file:


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >



    <Button

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Click here to visit Vissicomp" />


</LinearLayout>




No comments:

Post a Comment