android - SwipeListView only one item opened at a time -


this question refers swipelistview component found here: https://github.com/47deg/android-swipelistview

after trying out several implementations , fixes found on web decided modify sources little.

i post here since know it's known issue , versions found proved have issues eventually.

swipelistviewtouchlistener.java has suffered following changes:

... /**      * create reveal animation      *      * @param view      affected view      * @param swap      if change state. if "false" returns original      *                  position      * @param swapright if swap true, parameter tells if movement toward      *                  right or left      * @param position  list position      */     private void generaterevealanimate(final view view, final boolean swap, final boolean swapright, final int position) {         int moveto = 0;         if (opened.get(position)) {             if (!swap) {                 moveto = openedright.get(position) ? (int) (viewwidth - rightoffset) : (int) (-viewwidth + leftoffset);             }         } else {             if (swap) {                 moveto = swapright ? (int) (viewwidth - rightoffset) : (int) (-viewwidth + leftoffset);             }         }         final boolean aux = !opened.get(position);         if(swap) {             opened.set(position, aux);             openedright.set(position, swapright);         }          animate(view).translationx(moveto).setduration(animationtime).setlistener(new animatorlisteneradapter() {             @override             public void onanimationend(animator animation) {                 swipelistview.resetscrolling();                  if (swap) {                     if (aux) {                         swipelistview.onopened(position, swapright);                     } else {                         swipelistview.onclosed(position, openedright.get(position));                     }                 }                 // if (aux || !swap) {                 // resetcell();                 // }             }         });     } ...  /**      * close opened items      */      void closeotheropeneditems() {         if (opened != null && downposition != swipelistview.invalid_position) {             int start = swipelistview.getfirstvisibleposition();             int end = swipelistview.getlastvisibleposition();             (int = start; <= end; i++) {                 if (opened.get(i) && != downposition) {                     closeanimate(swipelistview.getchildat(i - start).findviewbyid(swipefrontview), i);                 }             }         }      } ...  /**      * @see view.ontouchlistener#ontouch(android.view.view,      * android.view.motionevent)      */     @override     public boolean ontouch(view view, motionevent motionevent) { ... closeotheropeneditems(); view.ontouchevent(motionevent); return true; } 

the rest of code not mentioned same.

any comments highly appreciated, changes prevent having implement swipelistviewontouchlistener in activity inflates list.

cons: doesn't close row opened openanimate()

   baseswipelistviewlistener swipelistviewlistener = new baseswipelistviewlistener() {     int openitem = -1;      @override     public void onstartopen(int position, int action, boolean right) {         super.onstartopen(position, action, right);          if (openitem > -1)             swipelistview.closeanimate(openitem);          openitem = position;     }    } 

or better way:

 @override     public void onstartopen(int position, int action, boolean right) {         super.onstartopen(position, action, right);         swipelistview.closeopeneditems();     } 

and set listener listview:

   swipelistview.setswipelistviewlistener(swipelistviewlistener); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -