我需要根据 ifStatement 的结果创建一个列表

发布于 2024-10-27 10:20:48 字数 631 浏览 0 评论 0原文

我有个问题要问你。我遇到的情况是,将根据 ifStatement 的结果生成一个列表。我的 ifStatement 基于是否选中复选框。如果是,我想要一个变量(比如说时间)存储在某处,直到用户被发送到一个新的活动,他/她将能够在其中查看结果。

换句话说,用户要么选中该复选框,要么不选中。如果他/她这样做了,我想跟踪发生这种情况的每个实例。当用户满足主 ifStatement 时(假设早餐结束),用户将能够看到有多少人选中了旁边的复选框:“addBacon”或其他......

希望这是有道理的。让我知道什么不可以,以便我可以澄清。

谢谢。

下面是代码示例:

case R.id.ButtonOK:
  if (examplecheckBox.isChecked()) {
     example++;
   if(examplecheckBox.isChecked()) {
     textexamplecounterID.setText(String.valueOf(example));

case R.id.ButtonNext: 
   if (example > 3) {
      Intent intent = new Intent(this, FinishActivity.class);
   }

I have a question for you. I have a situation where a list will be generated based on the results of an ifStatement. My ifStatement is based on whether a checkbox is checked. If it is, I want a variable (let's say, the time) stored somewhere until the user will be sent to a new activity where he/she will be able to view the results.

In other words, the user will either check the checkbox or not. If he/she does, I want to keep track of each instance that this happens. When the user satisfies the main ifStatement, (let's say, breakfast ends) the user will be able to see how many people checked the checkbox next to: "addBacon" or whatever...

hope this makes sense. Let me know what doesn't so that I can clarify.

Thank you.

Here's an example of the code:

case R.id.ButtonOK:
  if (examplecheckBox.isChecked()) {
     example++;
   if(examplecheckBox.isChecked()) {
     textexamplecounterID.setText(String.valueOf(example));

case R.id.ButtonNext: 
   if (example > 3) {
      Intent intent = new Intent(this, FinishActivity.class);
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2024-11-03 10:20:48

我不是 100% 确定你想要完成什么,但我认为对你有用的是使用 List 或 HashMap。当前工作(或接近工作)Activity 的代码以及可能的视图 xml 将使事情变得更容易,因为我们可以在上下文中看到问题,这可能会影响合理答案的构成。

如果所有订单总是有匹配的添加,那么只需有一个列表,其中订单号具有复选框。如果有些可能有 addBacon,而另一些可能有 addSausage,那么可能是 HashMap>。哈希图的键是要添加的成分,然后值是希望添加该成分的订单列表。然后,您将带有 Intent 的 List 或 HashMap 传递给您的下一个活动,该活动将对其进行迭代,统计所有内容并显示您的输出。

有更好的方法可以使用适合您的订单和成分的正确类来解决此问题,但我认为上述内容大致适合您当前正在寻找的内容。

I'm not 100% certain what you're trying to accomplish, but I think what might work for you is using a List or HashMap. The code for the current working (or close to working) Activity and possibly view xml would make it easier since we could see the problem in context, which can affect what constitutes a reasonable answer.

If all orders will always have matching add then just have a List with which order numbers had the checkbox. If some might have addBacon while some others may have addSausage then maybe a HashMap>. The keys of the hashmap would be what ingredient is to be added and then the value will be a list of the orders wanting that ingredient added. Then you pass the List or HashMap with the Intent to your next activity which will iterate over it, tally everything up, and display your output.

There are better ways to solve this using proper classes for your orders and ingredients, but the above I think roughly fits what you're currently looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文