2013-01-21 92 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