2011-08-26 4 views
1

Je suis un débutant android. Je fais un projet Android qui a pour fonction de réorganiser quelque chose dans une liste. J'ai trouvé une open source à https://github.com/commonsguy/cwac-touchlist#readme et le nom du module est CWAC: TouchListViewAndroid glisser et déposer des problèmes ListView

Mais lors de ma mise en œuvre, j'ai quelques problèmes et nous espérons que quelqu'un peut me aider,

  1. Je veux à TURNOFF le supprimer fonction lorsque je déplace l'élément de la liste à l'horizontale, mais je ne peux pas ... Si je commente le code de suppression à TouchListView.onTouchEvent() cas MotionEvent.ACTION_CANCEL Il se produira le comportement inattendu.

  2. En outre, je veux avoir quelque chose d'animation pendant le glissement de l'article comme la page de signet du navigateur Dolphin, mais je ne sais pas, il devrait implémenter le DragListener ??

Cependant, un bogue a été corrigé.

@Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     if (mGestureDetector != null) { 
      mGestureDetector.onTouchEvent(ev); 
     } 
     if ((mDragListener != null || mDropListener != null) && mDragView != null) { 
      int action = ev.getAction(); 
      switch (action) { 
      case MotionEvent.ACTION_UP: 
      case MotionEvent.ACTION_CANCEL: 
       Rect r = mTempRect; 
       mDragView.getDrawingRect(r); 
       stopDragging(); 

       if (mRemoveMode == SLIDE_RIGHT && ev.getX() > r.left + (r.width() * 3/4)) { 
        if (mRemoveListener != null) { 
         mRemoveListener.remove(mFirstDragPos); 
        } 
        unExpandViews(true); 
       } else if (mRemoveMode == SLIDE_LEFT && ev.getX() < r.left + (r.width()/4)) { 
        if (mRemoveListener != null) { 
         mRemoveListener.remove(mFirstDragPos);      
        } 
        unExpandViews(true); 
       } else { 
        if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount() - 1) { 
         mDropListener.drop(mFirstDragPos, mDragPos); 
        } 
        unExpandViews(false); 
       } 
       break; 

      case MotionEvent.ACTION_DOWN: 
      case MotionEvent.ACTION_MOVE: 
       int x = (int) ev.getX(); 
       int y = (int) ev.getY(); 
       dragView(x, y); 
       int itemnum = getItemForPosition(y); 
       if (itemnum >= 0) { 
        if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) { 
         if (mDragListener != null) { 
          mDragListener.drag(mDragPos, itemnum); 
         } 
         mDragPos = itemnum; 
         doExpansion(); 
        } 
        int speed = 0; 
        adjustScrollBounds(y); 
        if (y > mLowerBound) { 
         // scroll the list up a bit 
         speed = y > (mHeight + mLowerBound)/2 ? 16 : 4; 
        } else if (y < mUpperBound) { 
         // scroll the list down a bit 
         speed = y < mUpperBound/2 ? -16 : -4; 
        } 
        if (speed != 0) { 
         int ref = pointToPosition(0, mHeight/2); 
         if (ref == AdapterView.INVALID_POSITION) { 
          // we hit a divider or an invisible view, check 
          // somewhere else 
          ref = pointToPosition(0, mHeight/2 + getDividerHeight() + 64); 
         } 
         View v = getChildAt(ref - getFirstVisiblePosition()); 
         if (v != null) { 
          int pos = v.getTop(); 
          setSelectionFromTop(ref, pos - speed);       
         } 
        } 
       } 
       break; 
      } 
      return true; 
     } 
     return super.onTouchEvent(ev); 
    } 

Pour le cas MotionEvent.ACTION_CANCEL, si je fais glisser l'élément sur la list.getCount, il lancera exception, donc je remplacer la condition

de

if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) { 
     mDropListener.drop(mFirstDragPos, mDragPos); 
} 

à

if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount() - 1) { 
     mDropListener.drop(mFirstDragPos, mDragPos); 
} 

L'exception sera alors corrigée.

Quelqu'un peut-il m'aider? Merci beaucoup.

Répondre

0

Je veux à TURNOFF la fonction de suppression lorsque je déplace l'élément de liste à horizontal, mais je ne peux pas

Utilisez la commande remove_mode attribut avec une valeur de "none". Par exemple:

<?xml version="1.0" encoding="utf-8"?> 
<com.commonsware.cwac.tlv.TouchListView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tlv="http://schemas.android.com/apk/res/com.commonsware.cwac.tlv.demo" 

    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:drawSelectorOnTop="false" 
    tlv:normal_height="64dip" 
    tlv:grabber="@+id/icon" 
    tlv:remove_mode="none" 
/> 

Je veux avoir l'animation quelque chose lors de glisser l'élément comme la page des signets du navigateur de dauphins, mais je ne sais pas est-il

je ne serai pas en mesure de vous aider ça, désolé.

+0

Oh, merci. Je peux désactiver la fonction de suppression maintenant. Et je vais essayer d'implémenter l'animation. Je peux publier la solution si je peux implémenter cette fonction. – Rebecca

Questions connexes