关于两个活动的两个web_view

时间:2013-09-28 01:17:05

标签: java android

我刚开始学习Android_programming 我想在main_layout和web_view设置两个或多个链接到另一个活动(或布局更容易)所以我开始这个

public void onCreate(Bundle savedInstanceState) {

    final Context context = this;


    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main);

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

    button.setOnClickListener(new OnClickListener(){ 
          @Override
          public void onClick(View arg0) {
            Intent intent = new Intent(context, Web.class);
            startActivity(intent);
          }

        });}

public void onCreate1(Bundle savedInstanceState){   
final Context context1 = this;
super.onCreate(savedInstanceState); 

setContentView(R.layout.activity_main);
    button1 = (Button) findViewById(R.id.buttonUrl1);

    button1.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View arg0) {
        Intent i = new Intent(context1, Activity1.class);
        startActivity(i);
      }

    });

}

}

1 个答案:

答案 0 :(得分:0)

为什么你有onCreate和onCreate1?

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

        button.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(getApplicationContext(), Activity1.class);
                startActivity(intent);

            }

        });

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

        button1.setOnClickListener(new View.OnClickListener(){ 
              @Override
              public void onClick(View arg0) {
                Intent intent = new Intent(getApplicationContext(), Web.class);
                startActivity(intent);
              }

            });