0

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);
   }
Dr_GeoFry
  • 1
  • 2
  • If I understood you correctly you need global counters that count the clicks for each checkbox? – RoflcoptrException Mar 29 '11 at 18:00
  • I will only be using one checkbox. Let's say that a restaurant would only be taking 20 orders, and the checkbox would (at most) be checked one time per order order. I want to know which of the 20 orders used the checkbox. when all 20 orders are placed, I will be taken to a new activity where it will say, "addBacon" was clicked 13 times, on orders: 2, 3, 5, 7, 8, 9, 13, 15, 16, 17, 18, 19, 20. Since I won't know ahead of time, there is no way to hard code the results I would get for total times clicked and which orders got clicked. Again, sorry if this does not make sense. – Dr_GeoFry Mar 30 '11 at 07:48
  • Hmm ok difficult to imagine. Don't you have already a code snippet? It would be easier to imagine. – RoflcoptrException Mar 30 '11 at 09:21
  • @Roflcoptr, I do have code, but I was wondering how do I post it here and have it look presentable? Additionally, I am sure the code would more clearly show what it is I am attempting to do, but part of it will be empty since I do not know how to accomplish the task at hand. P.S. is there a way to indent or jump to the next line using the return key? – Dr_GeoFry Mar 31 '11 at 18:07
  • You can just edit your questions and input the code there. But I still don't know how to answer your question. Maybe some other guys can. Sorry. – RoflcoptrException Apr 01 '11 at 22:19
  • I hope you have the linebreaks in your code already? Just put it in here, Ill take a look and edit it if it doesnt look like it should – RoflcoptrException Apr 01 '11 at 22:26
  • @Roflcoptr, here is part of the code: `case R.id.ButtonOK: [linebreak] if (examplecheckBox.isChecked()) { example++; if (examplecheckBox.isChecked()) { textexamplecounterID.setText(String.valueOf(example));case R.id.ButtonNext: [linebreak]if (example > 3) { Intent intent = new Intent(this, FinishActivity.class);` something like this... as you can see, one part (example being greater than 3) is the main ifStatement. the first checkbox ifStatement is data that will form the list which will be viewed on FinishActivity. Is this getting easier to understand? – Dr_GeoFry Apr 01 '11 at 22:35
  • Yes i think I know what you want to do, but unfortunately I don't know the answer for your problem :( – RoflcoptrException Apr 01 '11 at 22:38
  • I think the problem is that you can't edit your post because of your low reputation. But if you post the code in a question and not a comment, the linebreak works automatically. – RoflcoptrException Apr 01 '11 at 23:35

1 Answers1

0

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.

jmichalicek
  • 2,398
  • 1
  • 17
  • 7