2013-01-21 63 views
0

荫试图onTouchListener但IAM运行应用到一些代码有问题,没有switchcase它是工作,将开关情况下,当它不是,下面是我的代码, 带开关的情况下代码如下OntouchListener工作不正常

if (phoneNo != null && !phoneNo.equals("") 
        && !phoneNo.equalsIgnoreCase("null")) { 
       textPhone.setText(phoneNo); 
       textPhone.setVisibility(View.VISIBLE); 
       phImage.setVisibility(View.VISIBLE); 

       phImage.setImageResource(R.drawable.phone); 
       phImage.setTag(phoneNo); 

       phImage.setOnTouchListener(new OnTouchListener() { 



        @Override 
        public boolean onTouch(View v, MotionEvent event) { 
         switch (event.getAction()) { 
         case MotionEvent.ACTION_DOWN: { 
         String phone = (String) ((ImageView) v).getTag(); 
         Log.d(TAG, "onTouch phone--" + phone); 
         utils.dailPhone(v.getContext(), phone); 
         return false; 
        } 
         }} 

       else { 
       phImage.setVisibility(View.GONE); 
       textPhone.setVisibility(View.GONE); 

      } 
       break; 
        case MotionEvent.ACTION_MOVE: 
         break; 
        case MotionEvent.ACTION_UP: 
         break; 
        } 

        return false; 
       } 

不低于

phImage.setOnTouchListener(new OnTouchListener() { 



       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        String phone = (String) ((ImageView) v).getTag(); 
        Log.d(TAG, "onTouch phone--" + phone); 
        utils.dailPhone(v.getContext(), phone); 
        return false; 
       } 
      }); 

     } else { 
      phImage.setVisibility(View.GONE); 
      textPhone.setVisibility(View.GONE); 

     } 

回答

2

你的switch-case语法swithcase是完全错误的。试试这样的:

public boolean onTouch(MotionEvent event) { 
    int eventaction = event.getAction(); 

    switch (eventaction) { 
     case MotionEvent.ACTION_DOWN: 
      // finger touches the screen 
      String phone = (String) ((ImageView) v).getTag(); 
      Log.d(TAG, "onTouch phone--" + phone); 
      utils.dailPhone(v.getContext(), phone); 
      return false; 
      break; 

     case MotionEvent.ACTION_MOVE: 
      // finger moves on the screen 
      break; 

     case MotionEvent.ACTION_UP: 
      // finger leaves the screen 
      break; 
    } 

    // tell the system that we handled the event and no further processing is required 
    return true; 
} 
+0

你可以修改我的代码从上面。 – teekib

+0

@teekib呃,是吗?它的正义代码。你可以修改它,无论你想要的方式 –

+0

这就是IAM面临的问题..修改代码在Eclipse中的一些错误。 – teekib