如何检查previous价值viewflipper的机器人 [英] how to check previous value in android of viewflipper

查看:217
本文介绍了如何检查previous价值viewflipper的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有八观鳍其中有4个问题和4答案。这是显示这些问题和答案,只要那个特定viewflipper被点击。我的问题是,当第一次任何viewflipper点击,在做那个时候什么都没有,和后viewflipper点击Next点击viewflipper值要检查是一样的(等于)还是不行。(如果问题是5 + 3则答案应该是8)。

条件:

  
      
  1. 如果我是第一次Q被点击,然后下一次另一viewflipper具有Q被点击任何检查操作是必要的,没有什么隐藏。

  2.   
  3. 如果我是第一次Q被点击,然后在下一次点击retrive从价值的Q TextView的,并检查它正确与否,如果它   是正确的隐藏两个问题与解答。

  4.   
  5. 如果我是第一次点击,然后下一个timeQ点击retrive值从A的TextView的,检查是不是正确与否,如果它   是正确的隐藏两个问题与解答。

  6.   
  7. 如果我是第一次点击,然后下一次另一viewflipper这haveA被点击任何检查操作是没什么必要隐藏。

  8.   
  9. 如果我是第一次Q被点击,然后下一次同样的viewflipper具有Q被点击任何检查操作是没什么必要隐藏。

  10.   
  11. 如果我点击第一次那么下一次同样的viewflipper其中有一个被点击任何检查操作是没什么必要隐藏。

  12.   

那么,如何查看当前可点击ViewFlipper和previous点击ViewFlipper。我没有任何想法如何检查问题。

看看这个,我想,我的问题是更清晰。

编辑:12月16日

  @覆盖
公共无效的onClick(视图v){

    开关(v.getId()){
    案例R.id.vf1:
        尝试 {
            如果(点击进入){
                消息味精=新的Message();
                msg.what = 1;
                delayHandler.sendMessageDelayed(味精,DELAYTIME);

                vFilpper1.showNext();


        }赶上(例外五){
            e.printStackTrace();
        }
        反++;
        打破;
    案例R.id.vf2:
        尝试 {
            消息味精=新的Message();
            msg.what = 2;
            delayHandler.sendMessageDelayed(味精,DELAYTIME);
            Log.d(viewfilpper,VFlipper 2);

            vFilpper2.showNext();


        }赶上(例外五){
            e.printStackTrace();
        }
        打破;
    案例R.id.vf3:
        尝试 {
            消息味精=新的Message();
            msg.what = 3;
            delayHandler.sendMessageDelayed(味精,DELAYTIME);
            Log.d(viewfilpper,VFlipper 3);
            vFilpper3.showNext();


        }赶上(例外五){
            e.printStackTrace();
        }
        打破;

    案例R.id.vf4:
        尝试 {
            消息味精=新的Message();
            msg.what = 4;
            delayHandler.sendMessageDelayed(味精,DELAYTIME);
            Log.d(viewfilpper,VFlipper 4);
            vFilpper4.showNext();

        }赶上(例外五){
            e.printStackTrace();
        }
        打破;
    案例R.id.vf5:
        尝试 {
            消息味精=新的Message();
            msg.what = 5;
            delayHandler.sendMessageDelayed(味精,DELAYTIME);
            Log.d(viewfilpper,VFlipper 5);
            vFilpper5.showNext();

        }赶上(例外五){
            e.printStackTrace();
        }
        打破;
    案例R.id.vf7:
        尝试 {
            消息味精=新的Message();
            msg.what = 7;
            delayHandler.sendMessageDelayed(味精,DELAYTIME);
            Log.d(viewfilpper,VFlipper 7);
            vFilpper7.showNext();


        }赶上(例外五){
            e.printStackTrace();
        }
        打破;
    案例R.id.vf8:
        尝试 {
            消息味精=新的Message();
            msg.what = 8;
            delayHandler.sendMessageDelayed(味精,DELAYTIME);
            Log.d(viewfilpper,VFlipper 8);
            vFilpper8.showNext();


        }赶上(例外五){
            e.printStackTrace();
        }
        打破;
 

解决方案

现在的问题是,你的code缺少的选择ViewFlipper的preVIOUS状态。我只能提供局部code,因为我不知道你的code中的其余部分。

在有你的code段放在这里的类中,公共无效的onClick(视图v){的方法,你想有这样的事情:

 公共类益智延伸活动{//或任何你的类被称为

    私人诠释previousFlipperID = -1; //这个存储的鳍状肢的所选择的previous状态

    @覆盖
    公共无效的onClick(视图v){
        // ....您的code,但修改
            //改变
        如果(previousFlipperID == -1){
            //这是第一个点击,使用-1 denotate,没有什么是previously选择
            previousFlipperID = v.getId();
            返回;
        }
            //结束变化

        开关(v.getId()){
        案例R.id.vf1:
        尝试 {
            如果(点击进入){

            //改变
                开关(previousFlipperID){
                情况下0:
                    //做你的逻辑,在这里,你说。注意,在这一点上,在code
                    //你的地步,你的preVIOUS脚蹼是第一脚蹼
                    //和当前鳍也是第一位的,因为v.getId()是R.id.vf1
                    打破;
                案例1://一些逻辑,但目前的鳍状肢是第一脚蹼,而preVIOUS脚蹼是第二升降
                    ...
                案例7://在previous鳍状肢选择的是最后的鳍状肢
                    打破;
                }
            //结束变化

                消息味精=新的Message();
                msg.what = 1;
                delayHandler.sendMessageDelayed(味精,DELAYTIME);

                vFilpper1.showNext();

        }赶上(例外五){
            e.printStackTrace();
        }
        反++;
        打破;

        //改变
        previousFliperID = v.getId(); //更新previous脚蹼
        //结束变化

    }
}
 

在我的code,寻找//改变更是如此。你会看到我用了一个整数存储previous鳍状肢。再这样,我检查,如果这是第一次,是检查previous脚蹼是-1与否。那么在最后,请确保您设置当前的鳍状肢ID为previous鳍ID更新previous脚蹼ID下一次。

另外请注意,我在那里一个嵌套的switch语句,因为你需要一堆额外的检查做你的逻辑会发生什么,这取决于当前和previous鳍状肢的。

答案是尽我的能力的信息我已经告诉(也尽我的理解),所以我希望这会有所帮助。

P.S。我感到内疚,这么说,但是如果我的回答是正确的,请请请检查我的答案,因为我确实需要一些赏金点问赏金的问题,但我不认为我有足够的积分。谢谢!而节日快乐

I Have eight View flipper which have 4 Question and 4 Answers. Which is display those Question and Answers, whenever that particular viewflipper is clicked. My problem is, When first time any viewflipper is clicked, at that time nothing to do, and after on viewflipper is clicked the next clicked viewflipper value want to check which is same(equal) or not.(If Question is 5+3 then answers should be 8).

Condition:

  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.

So, How to check Current clickable ViewFlipper and Previous clicked ViewFlipper. I did not get any idea how to check the problem.

Look at this, I think, my problem is more clear.

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;

解决方案

The problem is that your code is missing the state of the PREVIOUS selected ViewFlipper. I can only provide partial code as i don't know the rest of your code.

in the class which has your code snippet on 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 store the previous flipper. and then the way i check if it's the FIRST time, is to check if the previous flipper was -1 or not. then at the end, make sure you set the current flipper id as the previous flipper id to update the "previous" flipper id for the next time.

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

the answer is to the best of my abilities on information i've been told (and also to the best of my understanding), so i hope this helps.

P.S. i feel guilty say this, but if my answer was correct, please please please check my answer, because i actually need some bounty points to ask bounty questions but i don't think i have enough points. thanks! and happy holidays

这篇关于如何检查previous价值viewflipper的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆