I made a quiz application in android and after the user clicks on reset button i want all the marked answers to be unmarked or the app becomes same as when it started. How can i do so?
我在android中制作了一个测验应用程序,在用户点击重置按钮后,我希望所有标记的答案都没有标记,或者应用程序与启动时相同。我怎么能这样做?
The code for XML and JAVA are present in the following github repository. Code:
XML和JAVA的代码存在于以下github存储库中。码:
Here is a screenshot of the application. I want the app to be like starting when i click on the RESET button.
这是该应用程序的屏幕截图。当我点击RESET按钮时,我希望应用程序就像启动一样。
4 个解决方案
#1
3
Okay, after I read your source code from here I decided I shouldn't let you go on with that approach at all.
好的,在我从这里读到你的源代码后,我决定不让你继续这种方法。
Take some time, and read a little bit about RecyclerView and how it works, it will make your life way easier.
花一些时间,阅读一些关于RecyclerView以及它如何工作的内容,它将使您的生活更轻松。
Here is a tutorial on how to use it in a sample.
这是一个如何在示例中使用它的教程。
Once you get familiarized with it, I am sure you will make that screen look better and also the code will be much much more clear and well written.
一旦你熟悉它,我相信你会让这个屏幕看起来更好,而且代码也会更清晰,写得更好。
I could come with an approach for your particular case, but then you will copy paster it and that's it. Take some time, you'll like what you'll learn <3 If is really needed I will edit the answer with a simple implementation.
我可以为你的特定情况提供一种方法,但是你会复制贴纸它就是这样。花一些时间,你会喜欢你将学到的东西<3如果真的需要我会用简单的实现来编辑答案。
Happy coding <3
快乐编码<3
#2
0
//you can use this on reset button click for checkbox
if (checkBox1.isChecked()) {
checkBox1.setChecked(false);
}
if (checkBox2.isChecked()) {
checkBox2.setChecked(false);
}
#3
0
Pull all your checkbox in an Arraylist:
拉出Arraylist中的所有复选框:
ArrayList<CheckBox> checkboxList = new ArrayList<>();
checkboxList.add(checkbox1);
Then to remove all checkbox with check, try this:
然后使用check删除所有复选框,试试这个:
for(int i = 0; i < checkboxList.size(); i++) {
CheckBox checkBox = checkboxList.get(i);
checkBox.setChecked(false);
}
I suggest you to use recyclerview because your code is not the best approach. Hope this helps you.
我建议你使用recyclerview,因为你的代码不是最好的方法。希望这对你有所帮助。
#4
0
In your MainActivity's onCreate(...) method add this:
在MainActivity的onCreate(...)方法中添加以下内容:
Button resetButton=findViewById(R.id.button2);
resetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recreate();
}
});
It will call onDestroy() and restarts your Activity. Hope I could help! Regards, Cs
它将调用onDestroy()并重新启动您的Activity。希望我能帮忙!问候,Cs
#1
3
Okay, after I read your source code from here I decided I shouldn't let you go on with that approach at all.
好的,在我从这里读到你的源代码后,我决定不让你继续这种方法。
Take some time, and read a little bit about RecyclerView and how it works, it will make your life way easier.
花一些时间,阅读一些关于RecyclerView以及它如何工作的内容,它将使您的生活更轻松。
Here is a tutorial on how to use it in a sample.
这是一个如何在示例中使用它的教程。
Once you get familiarized with it, I am sure you will make that screen look better and also the code will be much much more clear and well written.
一旦你熟悉它,我相信你会让这个屏幕看起来更好,而且代码也会更清晰,写得更好。
I could come with an approach for your particular case, but then you will copy paster it and that's it. Take some time, you'll like what you'll learn <3 If is really needed I will edit the answer with a simple implementation.
我可以为你的特定情况提供一种方法,但是你会复制贴纸它就是这样。花一些时间,你会喜欢你将学到的东西<3如果真的需要我会用简单的实现来编辑答案。
Happy coding <3
快乐编码<3
#2
0
//you can use this on reset button click for checkbox
if (checkBox1.isChecked()) {
checkBox1.setChecked(false);
}
if (checkBox2.isChecked()) {
checkBox2.setChecked(false);
}
#3
0
Pull all your checkbox in an Arraylist:
拉出Arraylist中的所有复选框:
ArrayList<CheckBox> checkboxList = new ArrayList<>();
checkboxList.add(checkbox1);
Then to remove all checkbox with check, try this:
然后使用check删除所有复选框,试试这个:
for(int i = 0; i < checkboxList.size(); i++) {
CheckBox checkBox = checkboxList.get(i);
checkBox.setChecked(false);
}
I suggest you to use recyclerview because your code is not the best approach. Hope this helps you.
我建议你使用recyclerview,因为你的代码不是最好的方法。希望这对你有所帮助。
#4
0
In your MainActivity's onCreate(...) method add this:
在MainActivity的onCreate(...)方法中添加以下内容:
Button resetButton=findViewById(R.id.button2);
resetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recreate();
}
});
It will call onDestroy() and restarts your Activity. Hope I could help! Regards, Cs
它将调用onDestroy()并重新启动您的Activity。希望我能帮忙!问候,Cs