-1

I have created 2 buttons and i want to link both of them to 2 different html links,but i could link only one by using this below code....

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.content.Intent;
    import android.net.Uri;

    public class Main extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button btn = (Button) findViewById(R.id.button1);
            btn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                    myWebLink.setData(Uri.parse("http://........."));
                        startActivity(myWebLink);
                 }
            });

    }

Button btn2 = (Button) findViewById(R.id.button2);
        btn2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink2 = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink2.setData(Uri.parse("http://link2."));
                    startActivity(myWebLink2);
             }
        });

i got how to link button 2 to another link,but now i need button 3 to launch a next activity when we click on it,how ????

Give me step by step details if there is something to import or creating a class or so.....

Thanks in advance.

  • You clearly just copied code you don't understand and are asking someone to write the code for you. This and http://stackoverflow.com/q/21027895/2556111 – ramaral Jan 10 '14 at 21:21

1 Answers1

0

Check out the official tutorial for that. Basically, in your third button, you need to call startActivity with the appropriate intent, something like:

Button btn3 = (Button) findViewById(R.id.button3);
btn3.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent(Main.this, SecondActivity.class);
        startActivity(intent);
        }
    });

Where SecondActivity is the name of your second activity, so replace it with whatever you need.

npace
  • 4,218
  • 1
  • 25
  • 35