3

도움이 필요합니다 ... :-) ListView 용 사용자 지정 어댑터가 있습니다. 항목은 TextViews입니다. 모든 TextView에서 onSingleTap, onFling 및 기타 모든 이벤트를 처리 할 수 ​​있기를 원합니다. 그러나 onDown 이벤트 만 작동합니다! 다른 모든 사람들은 그렇지 않습니다! 나는 왜 그런지 이해하지 못한다. 당신이 사용자 정의 클래스 txtProductGestureDetector를 사용하는 경우OnFling 및 기타 메서드는 ListView 내 TextView에서 작동하지 않습니다.

public class ListViewAdapter extends BaseAdapter{ 
... 
private GestureDetector txtProductGD; 
private View.OnTouchListener txtProductGL; 
... 

public ListViewAdapter(Context context, ArrayList<Product> products) { 
    ... 
    txtProductGL = new View.OnTouchListener() { 
    public boolean onTouch(View v, MotionEvent event) { 
    txtProductGD = new GestureDetector(new txtProductGestureDetector((TextView) v)); 

    return txtProductGD.onTouchEvent(event); 
    } 
    }; 
    ... 
} 

public View getView(int position, View convertView, ViewGroup parent) { 
... 
view = inflater.inflate(R.layout.listview_item, null); 

TextView textView = (TextView) view.findViewById(R.id.txtProduct); 

textView.setOnTouchListener(txtProductGL); 
... 
} 

private class txtProductGestureDetector extends SimpleOnGestureListener { 

    private TextView textView; 

    public txtProductGestureDetector(TextView textView) { 
    this.textView = textView; 
    } 

    public boolean onDown (MotionEvent e) { 
    textView.setText("onDown..."); // IT WORKS! 
    return false; 
    } 

    public boolean onSingleTapConfirmed (MotionEvent e) { 
    textView.setText("onSingleTapConfirmed..."); // IT DOESN'T WORK! 
    return false; 
    } 

    // ALL OTHER METHODS ARE ALSO DON'T WORK!..  
}     
} 

답변

0

가 나도 몰라 : TextViews 모든 것이 잘 작동 ListView가의 일부가 아닌 내 다른 활동 ...에서

내가 가진 무엇 당신은 단지 특정 뷰에 대한 메소드를 오버라이드 (override) 할 찾고 있다면 또 다른 이유지만,이 시도 :

바로 getView 방법에 배치 할 수 있습니다, 당신의 텍스트 뷰에 touchListener를 할당합니다
TextView textView = (TextView) view.findViewById(R.id.txtProduct); 
textView.setOnTouchListener(new OnTouchListener() { 
    public boolean onTouch(View v, MotionEvent event) { 
     switch(event.getAction()) { 
      case (MotionEvent.ACTION_DOWN) : 
       Log.d(DEBUG_TAG,"Action was DOWN"); 
       return true; 
      case (MotionEvent.ACTION_MOVE) : 
       Log.d(DEBUG_TAG,"Action was MOVE"); 
       return true; 
      case (MotionEvent.ACTION_UP) : 
       Log.d(DEBUG_TAG,"Action was UP"); 
       return true; 
      case (MotionEvent.ACTION_CANCEL) : 
       Log.d(DEBUG_TAG,"Action was CANCEL"); 
       return true;  
      default : 
       return true; 
      }    
     } 
}); 

.