本文介绍了需要帮助就向左或向右轻扫数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android编程,我试图在向左或向右轻扫进行计数。

我想,当我刷卡从右到左是整数计数 ++ 高达10倍,但不会超过10。

当我向左或向右滑动它计算整数 - 下降到1不会低于1

请注意:我不是在谈论一个循环;我要的是,当我刷卡每一次它增加或减少诠释计数。

我试过是:

 包com.usd.swipegesture;进口android.app.Activity;
进口android.os.Bundle;
进口android.view.MotionEvent;
进口android.widget.TextView;
进口android.widget.Toast;公共类手势扩展活动{
    浮X1,X2;
    浮Y1,Y2;
    静态INT B:    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_gesture);
    }    // onTouchEvent(),当用户进行任何触摸事件方法被调用
    //屏幕
    //方法来处理触摸事件像左到右交换和从右到左
    //交换
    公共布尔onTouchEvent(MotionEvent的TouchEvent){
        开关(touchevent.getAction()){
        //当用户第一次触摸屏幕,我们得到x和y坐标
        案例MotionEvent.ACTION_DOWN:{
            X1 = touchevent.getX();
            Y1 = touchevent.getY();
            打破;
        }
        案例MotionEvent.ACTION_UP:{
            X2 = touchevent.getX();
            Y2 = touchevent.getY();            如果离开屏幕右侧掠过事件//
            如果(X1< X2){
                // Toast.makeText(这一点,左到右执行的交换,
                // Toast.LENGTH_LONG).show();                //
                b--;
                如果(B == 1){
                    B = 1;                    如果(B == 1){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(1);
                    }                    如果(B == 2){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(2);
                    }                    如果(B == 3){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(3);
                    }                    如果(二== 4){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(4);
                    }                    如果(二== 5){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(5);
                    }                    如果(二== 6){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(6);
                    }                    如果(二== 7){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(7);
                    }                    如果(二== 8){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(8);
                    }                    如果(二== 9){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(9);
                    }                    如果(二== 10){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(10);
                    }                }
                //
            }            //如果正确的在屏幕上向左扫事件
            如果(X1> X2){
                // Toast.makeText(这一点,右到左交换演出,
                // Toast.LENGTH_LONG).show();
                //
                基础B ++;
                如果(二== 10){
                    B = 10;                    如果(B == 1){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(1);
                    }                    如果(B == 2){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(2);
                    }                    如果(B == 3){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(3);
                    }                    如果(二== 4){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(4);
                    }                    如果(二== 5){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(5);
                    }                    如果(二== 6){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(6);
                    }                    如果(二== 7){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(7);
                    }                    如果(二== 8){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(8);
                    }                    如果(二== 9){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(9);
                    }                    如果(二== 10){
                        TextView的电视=(的TextView)findViewById(R.id.textView1);
                        tv.setText(10);
                    }
                }
                //
            }            打破;
        }
        }
        返回false;
    }
}

但它只能显示1到10的值。它没有显示1之间的任意值10。

我需要帮助纠正我的code。


解决方案

查看您$ C $再次C:

在这里看到:

 如果(二== 1){
     B = 1; // b为1,现在     如果(B == 1){//如果b为1,则执行此
          TextView的电视=(的TextView)findViewById(R.id.textView1);
          tv.setText(1);
     }
     .....

Similarly here :

if (b == 10) {
      b = 10; // b is now 10
      ......
      if (b == 10) { // if b is 10 then do this
          TextView tv = (TextView) findViewById(R.id.textView1);
          tv.setText("10");
      }

These 2 are the reasons why your code not showing other values between 1 to 10.

这篇关于需要帮助就向左或向右轻扫数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:46