我怎样才能点击一个又一个单选按钮时,让一个按钮在一个活动可见? [英] How can I make a button visible in one activity when clicking a radiobutton in another?

查看:132
本文介绍了我怎样才能点击一个又一个单选按钮时,让一个按钮在一个活动可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林通过点击一个单选按钮制作一个简单的Andr​​oidgame,当用户选择一个问题的答案(IND活动1)。当点击了正确的单选按钮,在信用(活性2)的按钮,将获得可见的,对用户是可用的。

Im making a simple Androidgame , where the user selects an answer to a question (ind Activity1) by clicking a radiobutton. When the correct radiobutton is clicked, a button in the "Credits" (Activity2) will get VISIBLE and be available for the user.

我怎样才能做到这一点?我不能让这两个活动一起工作?

How can I make this happen? i can´t get the two activities to work together?

从活动1(问题)的code其中用户点击单选:

The code from Activity 1 (the Question) where the user clicks the radiobutton:

 final Button s1 = (Button) findViewById(R.id.radio0);
 final Button s2 = (Button) findViewById(R.id.radio1);
 final Button s3 = (Button) findViewById(R.id.radio2);

 s1.setOnClickListener(new OnClickListener() { 
      public void onClick(View arg0) {
      btnEliminar.setVisibility(View.VISIBLE);
      btnKort.setVisibility(View.VISIBLE);
      s1.setVisibility(View.GONE);
      s2.setVisibility(View.GONE);
      s3.setVisibility(View.GONE);




      AlertDialog.Builder builder = new AlertDialog.Builder(Activity1.this);
        builder.setMessage("...");
        builder.setCancelable(true);
        builder.setPositiveButton("...", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();

                }
            });

        AlertDialog alert = builder.create();
        alert.show();

        }

  });

从活性2的code,其中的按钮应该可见:

The code from Activity2 where the button should get visible:

公共类活性2扩展活动{

public class Activity2 extends Activity {

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity2);

        Button credit1 = (Button) findViewById(R.id.buttoncredit1);
        credit1.setVisibility(View.INVISIBLE);
        ....
        credit1.setVisibility(View.VISIBLE);

希望有人能够帮助我
谢谢

Hope someone is able to help me Thank you

推荐答案

在活动1

    s1.setOnClickListener(new OnClickListener() { 
          public void onClick(View arg0) {

    Intent intent = new Intent(this,Activity2.class);

    if(s1.isChecked)
        intent.putExtra("state",0);
    else
        intent.putExtra("state",-1);

    startActivity(intent);

  });

在活动2

Intent intent = getIntent();
int state = Integer.parseInt(intent.getExtras().get("state").toString());
credit1.setVisibility(state);

希望这有助于

这篇关于我怎样才能点击一个又一个单选按钮时,让一个按钮在一个活动可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆