gpt4 book ai didi

java - 我已经创建了一个测验,但是我不确定如何使用 Parse 来实现捕获按下的按钮以检查答案

转载 作者:太空宇宙 更新时间:2023-11-04 14:06:28 24 4
gpt4 key购买 nike

我有四个按钮和一个 TextView 。使用以下代码从 Parse.com 检索 textView 中的文本:

final ParseQuery<ParseObject> quizOne = ParseQuery.getQuery("Quiz");
quizOne.getFirstInBackground(new GetCallback<ParseObject>() {

public void done(ParseObject reqDetails, ParseException e) {

if (quizOne != null) {
Log.d("quizOne", "Got it");
//Retrieve Age
String gettheQuestion = reqDetails.getString("questionOne");
TextView getQone = (TextView) findViewById(R.id.quesOne);
getQone.setText(gettheQuestion);
Toast.makeText(getApplicationContext(),
"Successfully Recieved Question",
Toast.LENGTH_LONG).show();


} else {
Log.d("quizOne", "Question not retreived.");
Toast.makeText(getApplicationContext(),
"Can't Get Details, Check Connection", Toast.LENGTH_LONG)
.show();
}
}
});

这是按钮的代码:

 optionAq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (optionAq.equals(optionAq)) {
Intent intent = new Intent(Quiz.this, Question2.class);
startActivity(intent);
}
}
});

optionBq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Quiz.this, Question2.class);
startActivity(intent);
}


});

optionCq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Quiz.this, Question2.class);
startActivity(intent);
}


});

optionDq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Quiz.this, Question2.class);
startActivity(intent);
}


});

我希望能够捕获按下的按钮并在之后显示结果屏幕。我该怎么做,有什么指示吗?

谢谢。

最佳答案

您不需要所有这些onClickListeners。您只需要一个包含多个 RadioButtonsRadioGroup 。您必须将其包含在 XML 布局中,如下所示:

 <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:orientation="vertical" >

<RadioButton
android:id="@+id/optionAq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="A" />

<RadioButton
android:id="@+id/optionAb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="B" />

<RadioButton
android:id="@+id/optionCb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="C" />

<RadioButton
android:id="@+id/optionDb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="D" />
</RadioGroup>

然后,在您的 Activity 中,您必须将 Buttons 更改为 RadioButtons

然后添加方法onRadioButtonClicked(),如果选择任何一个RadioButton,就会调用该方法。

public void onRadioButtonClicked(View v){
Log.i("Answer", "Answer is "+ ((RadioButton)v).getText());
Intent intent = new Intent(Quiz.this, Question2.class);
//send the answer to the next Activity if yo need
intent.putExtra("answer", ((RadioButton)v).getText());
//start next Activity
startActivity(intent);
}

根据您的实现,一旦单击 RadioButton 就启动一个新的 Activity,这是一个很好的方法。

还有许多其他方法,例如使用 radioGroup1.getCheckedRadioButtonId() 来获取选定的 RadioButton id。

无论如何,您可以在我之前评论中提供的 URL 中了解这一点以及更多信息。

关于java - 我已经创建了一个测验,但是我不确定如何使用 Parse 来实现捕获按下的按钮以检查答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28819609/

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