开发者

I need to create a list based on the results of an ifStatement

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 Int开发者_StackOverflow中文版ent(this, FinishActivity.class);
   }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜