How to check previous value in android viewflipper

I have a figure eight that has 4 questions and 4 answers . Display these Questions and Answers with each click on a particular click. My problem is that the first time a click on a click is clicked, there is nothing to do at that time, and after the next clicked viewflipper is clicked on the viewflipper click, I need to check if it is the same (equal) or not. (If the question is 5 + 3, then the answers should be 8).

Condition:

  • if I press Q for the first time, and then the next time when another viewflipper that has Q does not check anything, the operation is not needed and does not hide anything.

  • if I press the Q button for the first time, and then the next time A is pressed, select a value from the Q text view and check if it is correct or not, if it is right to hide both Q and A.

  • if I pressed A the first time, and then the next time Q a link to the value from the text representation of A will be clicked and check if it is correct or not, if it is right to hide both Q and A.

  • if I press A for the first time, and then the next time another viewflipper that hasA clicked does not check anything, the operation is not needed, it does not hide anything.

  • if I press Q for the first time, and then the next time the same viewflipper that has Q, the click does not check anything, the operation is not needed, it does not hide anything.

  • if I press A for the first time, and then the next time the same viewflipper that has A, clicking does not check anything, the operation does not hide anything.

So how to check the current Clickable ViewFlipper and Previous Click ViewFlipper. I did not understand how to check the problem.

Look at that, I think my problem is clearer.

enter image description here

Edited: Dec 16

@Override public void onClick(View v) { switch (v.getId()) { case R.id.vf1: try { if (click) { Message msg = new Message(); msg.what = 1; delayHandler.sendMessageDelayed(msg, DELAYTIME); vFilpper1.showNext(); } catch (Exception e) { e.printStackTrace(); } counter++; break; case R.id.vf2: try { Message msg = new Message(); msg.what = 2; delayHandler.sendMessageDelayed(msg, DELAYTIME); Log.d("viewfilpper", "VFlipper 2"); vFilpper2.showNext(); } catch (Exception e) { e.printStackTrace(); } break; case R.id.vf3: try { Message msg = new Message(); msg.what = 3; delayHandler.sendMessageDelayed(msg, DELAYTIME); Log.d("viewfilpper", "VFlipper 3"); vFilpper3.showNext(); } catch (Exception e) { e.printStackTrace(); } break; case R.id.vf4: try { Message msg = new Message(); msg.what = 4; delayHandler.sendMessageDelayed(msg, DELAYTIME); Log.d("viewfilpper", "VFlipper 4"); vFilpper4.showNext(); } catch (Exception e) { e.printStackTrace(); } break; case R.id.vf5: try { Message msg = new Message(); msg.what = 5; delayHandler.sendMessageDelayed(msg, DELAYTIME); Log.d("viewfilpper", "VFlipper 5"); vFilpper5.showNext(); } catch (Exception e) { e.printStackTrace(); } break; case R.id.vf7: try { Message msg = new Message(); msg.what = 7; delayHandler.sendMessageDelayed(msg, DELAYTIME); Log.d("viewfilpper", "VFlipper 7"); vFilpper7.showNext(); } catch (Exception e) { e.printStackTrace(); } break; case R.id.vf8: try { Message msg = new Message(); msg.what = 8; delayHandler.sendMessageDelayed(msg, DELAYTIME); Log.d("viewfilpper", "VFlipper 8"); vFilpper8.showNext(); } catch (Exception e) { e.printStackTrace(); } break; 
+6
source share
2 answers

The problem is that your code is missing the state of the selected PREVIOUS ViewFlipper. I can only provide partial code, since I do not know the rest of your code.

in the class that contains the code snippet here, the public void onClick (View v) {"method, you want to have something like this:

 public class Puzzle extends Activity{ //or whatever your class is called private int previousFlipperID = -1; //this stores the previous state of the flipper that was selected @Override public void onClick(View v) { //.... your code, but modified // changes if(previousFlipperID == -1){ //this is the VERY FIRST CLICK, using -1 to denotate that nothing was previously selected previousFlipperID = v.getId(); return; } // end changes switch (v.getId()) { case R.id.vf1: try { if (click) { // changes switch(previousFlipperID){ case 0: //do your logic here that you stated. note that at this point in the code // you are at the point where your PREVIOUS flipper was the first flipper // and your CURRENT flipper is also the first one, since v.getId() is R.id.vf1 break; case 1: //some logic, but the CURRENT flipper is the first flipper, while PREVIOUS flipper was the second flipper ... case 7: //the previous flipper selected was the last flipper break; } // end changes Message msg = new Message(); msg.what = 1; delayHandler.sendMessageDelayed(msg, DELAYTIME); vFilpper1.showNext(); } catch (Exception e) { e.printStackTrace(); } counter++; break; // changes previousFliperID = v.getId(); //update the previous flipper // end changes } } 

in my code, look for "// changes" especially. you'll see that I used an integer to hold the previous flipper. and then, as I check, if this is the first time, I need to check if the previous flipper was -1 or not. then, at the end, make sure you set the current flipper identifier as the previous flipper identifier in order to update the β€œprevious” flipper identifier next time.

also note that I had a nested switch statement, because you need a bunch of extra checks to make your logic for what happens, depending on what the current and previous flippers are.

the answer to all my abilities regarding the information that I talked about (as well as to my knowledge), so I hope this helps.

PS I feel guilty, but if my answer was correct, please, please check my answer, because I really need some bonus points to ask questions about bonuses, but I do not think that I have enough points. thank you and happy holidays

+3
source

Well, you don't have code that shows how you switch between your views, but here it goes: when you switch the code to your click or whatever you set membervariable to last = currentselected and currentselected = id of the selected viewflipper. Really dead is simple. Oh, and the first time you check to see if it's zero. If you want me to be a more accurate delivery code that shows how you switch between your views.

0
source

Source: https://habr.com/ru/post/903816/


All Articles