gpt4 book ai didi

android - 如何在viewflipper的android中检查以前的值

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:01 25 4
gpt4 key购买 nike

我有八个 View flipper,其中有 4 个问题和 4 个答案。每当单击特定的 viewflipper 时,就会显示这些问题和答案。我的问题是,当第一次单击任何 viewflipper 时,当时无事可做,在单击 viewflipper 后,下一个单击的 viewflipper 值想要检查哪个相同(相等)或不同。(如果问题是 5+3 那么答案应该是 8)。

条件:

  1. if I am first time Q is clicked then next time another viewflipper which have Q is clicked nothing check operation is necessary and nothing hide .

  2. if I am first time Q is clicked then next time A is clicked retrive value from textview of Q and check is it right or not, if it is right hide both Q and A.

  3. if I am first time A is clicked then next timeQ is clicked retrive value from textview of A and check is it right or not, if it is right hide both Q and A.

  4. if I am first time A is clicked then next time another viewflipper which haveA is clicked nothing check operation is necessary nothing hide.

  5. if I am first time Q is clicked then next time same viewflipper which have Q is clicked nothing check operation is necessary nothing hide.

  6. if I am first time A is clicked then next time same viewflipper which have A is clicked nothing check operation is necessary nothing hide.

那么,如何检查当前可点击的 ViewFlipper 和上一个点击的 ViewFlipper。我不知道如何检查问题。

看看这个,我想,我的问题更清楚了。

enter image description here

编辑:12 月 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;

最佳答案

问题是您的代码缺少先前选择的 ViewFlipper 的状态。我只能提供部分代码,因为我不知道您的其余代码。

在此处有您的代码 fragment 的类中,“public void onClick(View v) {”方法中,您想要这样的东西:

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

}
}

在我的代码中,特别要查找“//changes”。你会看到我使用了一个整数来存储前一个脚蹼。然后我检查它是否是第一次的方法是检查前一个脚蹼是否为 -1。然后在最后,确保将当前的鳍状肢 ID 设置为以前的鳍状肢 ID,以便下次更新“以前的”鳍状肢 ID。

另外,请注意,我在其中有一个嵌套的 switch 语句,因为您需要一堆额外的检查来对发生的事情执行您的逻辑,具体取决于当前和之前的脚蹼是什么。

答案是根据我所获信息的最佳能力(也是我的最佳理解),所以我希望这会有所帮助。

附言这么说我感到内疚,但如果我的回答是正确的,请检查我的答案,因为我实际上需要一些赏金点数来提出赏金问题,但我认为我没有足够的点数。谢谢!和节日快乐

关于android - 如何在viewflipper的android中检查以前的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8515802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com