-1

嘿伙计们,我正在尝试创建一个测验,但我的意图有问题,在用户单击按钮后,它会自动意图进行另一个活动.. 我该怎么做?

请帮助大家...提前谢谢..

这是代码:

if(btn1.isClickable())
    {
        img1.setVisibility(View.VISIBLE);
        img1.setImageResource(R.drawable.check);

        img2.setVisibility(View.INVISIBLE);
        img2.setImageResource(R.drawable.wrong);

        img3.setVisibility(View.INVISIBLE);
        img3.setImageResource(R.drawable.wrong);

        btn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Scorecount++;
                Intent i = getIntent();
                startActivity(i);
                Scorecount = i.getIntExtra("score",0);

            }
        });

    }
    else if (btn2.isClickable())
    {
        img2.setVisibility(View.VISIBLE);
        img2.setImageResource(R.drawable.wrong);

        img1.setVisibility(View.INVISIBLE);
        img1.setImageResource(R.drawable.wrong);

        img3.setVisibility(View.INVISIBLE);
        img3.setImageResource(R.drawable.wrong);
    }
    else if (btn3.isClickable())
    {
        img3.setVisibility(View.VISIBLE);
        img3.setImageResource(R.drawable.wrong);

        img2.setVisibility(View.INVISIBLE);
        img2.setImageResource(R.drawable.wrong);

        img1.setVisibility(View.INVISIBLE);
        img1.setImageResource(R.drawable.wrong);
    }
    btn1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent i = getIntent();
            startActivity(i);
            Scorecount = i.getIntExtra("score",0);

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

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent i = getIntent();
            startActivity(i);

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

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent i = getIntent();
            startActivity(i);
        }
    });
}

}

4

3 回答 3

0

第一项活动

Intent i= new Intent(CurrentActivity.this,
                    NextActivity.class);

            i.putExtra("quiz", array[0]);
            i.putExtra("pass_value","Pass value");
            startActivity(i);

第二次活动

String getvalue= getIntent().getSerializableExtra("pass_value").toString();
于 2013-01-30T11:51:08.033 回答
0

我不确定我是否完全理解你想要什么,但你可以将一个意图添加到另一个意图,因为意图实现 parceable。你可以这样做:

intent.putExtra("INTENT_KEY", someOtherIntent);

接着:

intent = getIntent();
Intent someOtherIntent = (Intent)intent.getParcelableExtra("INTENT_KEY");

它有帮助吗?

PS你的代码很奇怪......(我的意思有时是错误的和毫无意义的)

于 2013-01-30T11:56:47.367 回答
0

为了传递参数,您创建新意图并放置参数映射:

Intent myIntent = new Intent(this, NewActivityClassName.class);
myIntent.putExtra("firstKeyName","FirstKeyValue");
myIntent.putExtra("secondKeyName","SecondKeyValue");
startActivity(myIntent);

为了获取参数值,您必须get[type]Extra()以相同的意图调用:

Intent myIntent= getIntent(); // gets the previously created intent
String firstKeyName = intent.getStringExtra("firstKeyName"); // will return "FirstKeyValue"
String firstKeyName = intent.getStringExtra("firstKeyName"); // will return "SecondKeyValue"

如果您的参数是整数,您将使用getIntExtra()等。现在您可以像往常一样使用您的参数。

于 2013-01-30T12:00:29.987 回答