打开另一个活动时出错?

时间:2016-09-15 10:55:58

标签: android android-activity

当我点击Activity btnFemaleButton btnMale时,我只想尝试打开另一个Button。现在btnfemale {{ 1}}效果很好,但Button btnMale无效。

Button

4 个答案:

答案 0 :(得分:4)

创建单独的侦听器,而不是另一个

server {
  listen 443 ssl;
  server_name my-sites.com;
  ssl_certificate /etc/nginx/ssl/my-sites.com/uni_my-sites.com.crt;
  ssl_certificate_key /etc/nginx/ssl/my-sites.com/my-sites.com.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

  client_max_body_size 30m;

  location / {
    proxy_pass http://my-backend.com;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}

点击BtnFemale.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(),ActivityTwo.class); startActivity(intent); } }); BtnMale.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ Intent intent = new Intent(getApplicationContext(),ActivityThree.class); startActivity(intent); } }); 时,您正在添加BtnMale的听众。

答案 1 :(得分:1)

将您的代码更改为 BtnFemale.setOnClickListener(new View.OnClickListener(){     @覆盖     public void onClick(查看v){         Intent intent = new Intent(getApplicationContext(),ActivityTwo.class);         startActivity(意向);     } }); BtnMale.setOnClickListener(new View.OnClickListener(){             @覆盖             public void onClick(查看v){                 Intent intent = new Intent(getApplicationContext(),ActivityThree.class);                 startActivity(意向);             }             });

答案 2 :(得分:1)

 Button BtnFemale = (Button)findViewById(R.id.btnFemale);
        final Button BtnMale = (Button) findViewById(R.id.btnMale);

        BtnFemale.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), ActivityTwo.class);
                startActivity(intent);
            }
            });


                BtnMale.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v){

                        Intent intent = new Intent(getApplicationContext(),ActivityThree.class);
                        startActivity(intent);
                    }
                });

更正您的代码括号未妥善管理

答案 3 :(得分:1)

为按钮创建单独的侦听器 请点击以下链接。 Best practice for defining button events in android

$('#collapseDiv').on('shown.bs.collapse', function () {
       $(".glyphicon").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
    });

    $('#collapseDiv').on('hidden.bs.collapse', function () {
       $(".glyphicon").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
    });