2017-05-26 138 views
-3

我需要一些幫助與我的android程序。我需要在每次觸摸時出現幾個TextView。 1st touch = TextView1,2nd touch = TextView2等。我試圖在ACTION_DOWN之後用ACTION_POINTER_DOWN做它,但它在一次觸摸中顯示所有文本視圖。Android開發:第一個觸摸= TextView1,第二個觸摸= TextView2等

public boolean onTouch(View v, MotionEvent event) { 

boolean inTouch = false; 

     int actionMask = event.getActionMasked(); 
     tv = (TextView) findViewById(R.id.textView3); 
     tv1 = (TextView) findViewById(R.id.textView4); 
     tv2 = (TextView) findViewById(R.id.textView5); 
     tv3 = (TextView) findViewById(R.id.textView6); 
     int pointerCount = event.getPointerCount(); 
     int downPI = 0; 
     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: // 1st touch 
       inTouch = true; 

      case MotionEvent.ACTION_POINTER_DOWN: // next touches 
         downPI = pointerCount; 
         switch (downPI) { 
          case 0: 
           tv.setVisibility(View.VISIBLE); 
           break; 
          case 1: 
           tv1.setVisibility(View.VISIBLE); 
           break; 
          case 2: 
           tv2.setVisibility(View.VISIBLE); 
           break; 
          case 3: 
           tv3.setVisibility(View.VISIBLE); 
           break; 

         } 
         break; 


     } 

      return false; 
+1

您在'ACTION_UP'檢查,因爲'ACTION_DOWN'被觸發經常 – Denny

回答

0

嘗試以下解決方案: -

只需添加以下線以上onCreate()(定義變量): -

int downPI = 0; 

而且下面一樣,在onTouch代碼註釋: -

//    downPI = pointerCount; 

return false;之前的增量如: -

if(downPI < 3) 
     downPI++; 

    return false; 
+0

非常感謝,我只是在想pointerCount應與每個觸摸 – Anastasiya

+0

沒問題,改變它'值。有時,替代方式在編碼方面更好。 –

相關問題