Android RecyclerView item foreground/background swipe issue -


i've tried use recyclerview in android project, , works fine instead of swipe touch handling. approach custom view (mainly buttons), under list items. see screenshot below: swipeable item background expectation

i find way how perform animation, can't click on button on background view. guess problem touchlistener still wants perform swipe effect instead of click event, because "swipeable area" still complete width of view (foreground , background). there known workaround or best practice handle click events under main item? or can make foreground swipeable?

here code snippets.

touch listener:

public class traininglistonswipeanddraglistener extends itemtouchhelper.simplecallback {   private final mainactivity activity; private trainingroutinelistadapter adapter;   public traininglistonswipeanddraglistener(mainactivity activity, trainingroutinelistadapter adapter, int dragdirs, int swipedirs) {     super(dragdirs, swipedirs);     this.activity = activity;     this.adapter = adapter; }  @override public boolean islongpressdragenabled() {     return true; }  @override public boolean isitemviewswipeenabled() {     return true; }  @override public boolean onmove(recyclerview recyclerview, recyclerview.viewholder viewholder, recyclerview.viewholder target) {     return adapter.onitemmove(viewholder.getadapterposition(), target.getadapterposition()); }  @override public void onswiped(recyclerview.viewholder viewholder, int direction) { }  @override public void onchilddraw(canvas c, final recyclerview recyclerview, final recyclerview.viewholder viewholder, float dx, float dy, int actionstate, boolean iscurrentlyactive) {      if(actionstate == itemtouchhelper.action_state_swipe) {         view itemview = ((routineviewholder) viewholder).foreground;         itemview.settranslationx(dx / 2);     }else{         super.onchilddraw(c, recyclerview, viewholder, dx, dy, actionstate, iscurrentlyactive);     }  }  } 

item layout xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lltrainingexerciselayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="1dp" android:clickable="true" android:focusable="true">  <relativelayout     android:id="@+id/background"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@color/bg_extra_dark"     android:paddingbottom="8dp"     android:paddingtop="8dp"     android:visibility="visible">      <imageview         android:id="@+id/deletetrset"         android:layout_width="50dp"         android:layout_height="50dp"         android:layout_alignparentright="true"         android:layout_marginbottom="5dp"         android:layout_margintop="5dp"         android:padding="5dp"         android:src="@drawable/trash_neon_48"         android:clickable="true"/>      <imageview         android:id="@+id/edittrset"         android:layout_width="50dp"         android:layout_height="50dp"         android:layout_aligntop="@+id/deletetrset"         android:layout_toleftof="@+id/deletetrset"         android:layout_tostartof="@+id/deletetrset"         android:padding="10dp"         android:src="@drawable/edit_neon_50"         android:clickable="true"/>  </relativelayout>  <relativelayout     android:id="@+id/foreground"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@drawable/calendar_background_statelist"     android:paddingbottom="8dp"     android:paddingtop="8dp"     android:visibility="visible">      <imageview         android:id="@+id/imgtrainingactivityimage"         android:layout_width="50dp"         android:layout_height="50dp"         android:layout_gravity="center_horizontal"         android:layout_marginbottom="5dp"         android:layout_marginleft="5dp"         android:layout_marginright="10dp"         android:layout_margintop="5dp"         android:background="@drawable/navdrawer_list_item_icon_backgroud"         android:padding="5dp"         android:src="@drawable/bear_footprint_50" />      <textview         android:id="@+id/tvtrainingactivitytitle"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_aligntop="@+id/imgtrainingactivityimage"         android:layout_toendof="@+id/imgtrainingactivityimage"         android:layout_torightof="@+id/imgtrainingactivityimage"         android:text="fekvőtámasz"         android:textcolor="@color/text_white"         android:textsize="14sp" />       <textview         android:id="@+id/tvtrainingactivitysetandreps"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignleft="@+id/tvtrainingactivitytitle"         android:layout_alignstart="@+id/tvtrainingactivitytitle"         android:layout_below="@+id/tvtrainingactivitytitle"         android:layout_gravity="center_horizontal"         android:layout_margin="2dp"         android:text="2 x 12"         android:textcolor="@color/text_white"         android:textsize="@dimen/abc_text_size_medium_material" />   </relativelayout>   </relativelayout> 

adapter:

public class trainingroutinelistadapter extends recyclerview.adapter<routineviewholder> implements calendarclickcallback{  private mainactivity activity; private customfragmentfactory fragmentfactory; private list<trainingset> mdata;  public void setmdata(list<trainingset> mdata) {     this.mdata = mdata; }  public trainingroutinelistadapter(mainactivity activity, list<trainingset> mdata) {     this.activity = activity;     this.fragmentfactory = customfragmentfactory.getcustomfragmentfactory();     this.mdata = mdata; }  @override public routineviewholder oncreateviewholder(viewgroup parent, int viewtype){     view itemview = layoutinflater.from(activity).inflate(r.layout.trainingroutine_listitem_layout,parent,false);      return new routineviewholder(itemview); }  @override public void onbindviewholder(routineviewholder holder, final int position) {      holder.exercisename.settext(mdata.get(position).getmexercise().getmname());     holder.icon.setimagebitmap(convert_utils.decodebase64(mdata.get(position).getmexercise().getmicon().getmbase64string()));     string reps ="";     string weight = "";     string time = "";     if ( mdata.get(position).getmreps() != 0){         reps = mdata.get(position).getmreps() + " ism";     }     if ( mdata.get(position).getmweight() != 0){         weight = " ("+mdata.get(position).getmweight() + " kg)";     }     if ( mdata.get(position).getmtime() != 0){         time = new simpledateformat("mm:ss.ss").format(new date(mdata.get(position).getmtime()));     }     holder.setsrepstime.settext(reps + weight + time);     holder.editsetbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             oneditrowclicked(position);         }     });      holder.deletesetbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             ondeleterowclicked(position);         }     }); }  @override public int getitemcount() {     return mdata.size(); }   public void additem(trainingset set) {     mdata.add(set);     notifyiteminserted(mdata.size()); }  public void removeitem(int position) {     mdata.remove(position);     notifyitemremoved(position);     notifyitemrangechanged(position, mdata.size()); }   public boolean onitemmove(int fromposition, int toposition) {     if (fromposition < toposition) {         (int = fromposition; < toposition; i++) {             collections.swap(mdata, i, + 1);         }     } else {         (int = fromposition; > toposition; i--) {             collections.swap(mdata, i, - 1);         }     }     notifyitemmoved(fromposition, toposition);     return true; }  @override public void onitemclick(view view, int position) {     bundle data = new bundle();     data.putparcelable("exercise", mdata.get(position).getmexercise());     data.putboolean("isnewexercise", true);     data.putboolean("appbarrestore", false);      fragmentfactory.changecontentfragment(activity, "fragment_3_details", data, fragmenttransaction.transit_fragment_open, true); }  @override public void onitemlongclick(view view, int position) {     //toast.maketext(activity, "long clicked (" + position + ")", toast.length_short).show(); }    public void oneditrowclicked(int position) {     toast.maketext(activity, "edit button clicked (" + position + ")", toast.length_short).show(); }   public void ondeleterowclicked(int position) {     toast.maketext(activity, "delete button clicked (" + position + ")", toast.length_short).show(); } } 

as i'm beginner in android, comments , hints welcome.

thank in advance,


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -