如何有多个按钮在一种活性多个、活性、按钮

2023-09-06 13:29:09 作者:女痞

有很多按钮,我的Andr​​oid应用程序。

我的main.xml中的布局有三个按钮。

我知道如何使用按钮从一个活动到另一个去,但我不知道如何有一个活动的多个按钮,每个发射比其他不同的活动。

例如:

的main.xml

Button1的 按钮2

Main2.xml

按按钮1推出

About.xml

通过将Button2推出

如何让我的main.java文件做到这一点?

解决方案

 公共类NL延伸活动{



     公共无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.main);
          按钮B1 =(按钮)findViewById(R.id.Button01);
          按钮B2 =(按钮)findViewById(R.id.Button02);
          b1.setOnClickListener(新View.OnClickListener(){

            公共无效的onClick(视图v){
                意图myintent2 =新的意图(NL.this,Button1.class);
                startActivity(myintent2);

            }
        });
          b2.setOnClickListener(新View.OnClickListener(){

                公共无效的onClick(视图v){
                    意图myintent2 =新的意图(NL.this,Button2.class);
                    startActivity(myintent2);

                }
            });
    }
}
 

此举从一个活动到另一个活动使用intent.we写code。在按钮的点击监听器

多个控件怎样共享一个按钮啊

My Android app having many buttons.

My main.xml layout has three buttons.

I know how to use buttons to go from one activity to another, But i don't know how to have multiple buttons on one activity, with each launching a different activity than the other.

EXAMPLE

Main.xml

Button1 Button2

Main2.xml

Launched by button1

About.xml

Launched by Button2

How do i make the main.java file do this?

解决方案

public class NL extends Activity {



     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
          Button b1=(Button)findViewById(R.id.Button01);
          Button b2=(Button)findViewById(R.id.Button02);
          b1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent myintent2 = new Intent(NL.this,Button1.class);
                startActivity(myintent2);

            }
        });
          b2.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    Intent myintent2 = new Intent(NL.this,Button2.class);
                    startActivity(myintent2);

                }
            }); 
    }
}

move from one activity to another activity using intent.we write that code in button click listener

 
精彩推荐
图片推荐