gpt4 book ai didi

java - 如何根据选择的单选按钮打开特定 Activity ?

转载 作者:行者123 更新时间:2023-12-01 13:18:58 26 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,其中“登录” Activity 包含 2 个单选按钮(经理和团队负责人)以及一个“继续”按钮。如果选择了经理单选按钮,则如果选择了团队负责人单选按钮,则将打开经理调查问卷 Activity 团队领导问卷必须打开。任何人都可以帮我修改java代码吗?提前致谢。

This is my login activity

public void OnClickListener(View v)
{
final RadioButton manager = (RadioButton) findViewById(R.id.radioButton1);
final RadioButton teamleader = (RadioButton) findViewById(R.id.radioButton2);

Button proceed = (Button) findViewById(R.id.button1);
proceed.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{

if(manager.isChecked())
{
Intent managerIntent = new Intent(getApplicationContext(), ManagerQuestionnaire1.class);
startActivityForResult(managerIntent, 0);
}
else
{
if(teamleader.isChecked())
{
Intent teamleaderIntent = new Intent(getApplicationContext(), TeamleaderQuestionnaire1.class);
startActivityForResult(teamleaderIntent, 0);
}
}
}
});
}

这是按钮的 Xml 代码(继续)

 <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="OnClickListener"
android:text="@string/Proceed_b1" />

最佳答案

试一下:

public void OnClickListener(View v)
{
final RadioButton manager = (RadioButton) findViewById(R.id.radioButton1);
final RadioButton teamleader = (RadioButton) findViewById(R.id.radioButton2);

Button proceed = (Button) findViewById(R.id.button1);
proceed.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{

if(manager.isChecked()) {
Intent managerIntent = new Intent(getApplicationContext(), ManagerQuestionnaire1.class);
startActivityForResult(managerIntent, 0);
} else if (teamleader.isChecked()) {
Intent teamleaderIntent = new Intent(getApplicationContext(), TeamleaderQuestionnaire1.class);
startActivityForResult(teamleaderIntent, 0);
}
});
}

您的代码的问题在于:

if(teamleader.isChecked())

嵌套在:

if(manager.isChecked())

这意味着只有在开始检查经理时它才会命中!

希望有所帮助,编码愉快。

关于java - 如何根据选择的单选按钮打开特定 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22206563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com