Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Set different OnTouch event on every child
    primarykey
    data
    text
    <p>Hello I'm trying to create a drag and drop view and I have succeed but I have one problem, I add my view dynamically like this</p> <pre><code>int k=0; for(int i=0;i&lt;badge_list_id.size()/2;i++) { Log.i(BaseID.TAG, "K : "+k); temp_badge_list_id.clear(); temp_badge_list_name.clear(); temp_badge_list_url.clear(); for(int j=k;j&lt;k+2;j++) { temp_badge_list_id.add(badge_list_id.get(j)); temp_badge_list_name.add(badge_list_name.get(j)); temp_badge_list_url.add(badge_list_url.get(j)); } llContainerBadgeList.addView(new ChildPopUpTopSend(context, temp_badge_list_id, temp_badge_list_name, temp_badge_list_url, badge_id, new callbackDragDrop())); k=k+2; } </code></pre> <p>and set the ontouch listener in the childview like this</p> <pre><code>private View.OnTouchListener mOnTouchDrag1=new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_MOVE: { cbDrag.onDrag(badge_list_id.get(0), badge_id, BaseID.DRAGGING, event, v, badge_list_url.get(0)); break; }//inner case MOVE case MotionEvent.ACTION_UP: { cbDrag.onDrag(badge_list_id.get(0), badge_id, BaseID.STOP_DRAG, event, v, badge_list_url.get(0)); break; }//inner case UP case MotionEvent.ACTION_DOWN: { cbDrag.onDrag(badge_list_id.get(0), badge_id, BaseID.START_DRAG, event, v, badge_list_url.get(0)); break; }//inner case UP }//inner switch return true; } }; </code></pre> <p>and the cbDrag.onDrag function is like this</p> <pre><code>private class callbackDragDrop implements callbackDrag { @Override public void onDrag(int selected_badge, ArrayList&lt;Integer&gt; badge_id, int dragState, MotionEvent event, View v, String badge_url) { LinearLayout.LayoutParams par = (LinearLayout.LayoutParams) v.getLayoutParams(); switch(dragState) { case BaseID.START_DRAG: llContainerDrag = new LinearLayout(context); llContainerDrag.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, (Util.getDisplayHeight(context)*8)/10)); ivDrag = new ImageView(context); imageLoader.DisplayImage(badge_url, ivDrag); par.topMargin = (int)event.getRawY() - (int)(v.getHeight()*1.5); par.leftMargin = (int)event.getRawX() - (int)(v.getWidth()*1.5); ivDrag.setLayoutParams(par); llContainerDrag.addView(ivDrag); PopUpTopSend.this.addView(llContainerDrag); break; case BaseID.DRAGGING: par.height = drag_height; par.width = drag_width; par.topMargin = (int)event.getRawY() - (int)(v.getHeight()*1.5); par.leftMargin = (int)event.getRawX() - (int)(v.getWidth()*1.5); ivDrag.setLayoutParams(par); break; case BaseID.STOP_DRAG: int drop_position = checkDropLocation(event); Log.i(BaseID.TAG, "Drop position : "+drop_position); ImageView ivDrop; switch(drop_position) { case 1: if(selected_badge!=badge_id.get(0)) { ivDrop = (ImageView) findViewById(R.id.ivBadgeSend1); imageLoader.DisplayImage(badge_url, ivDrop); PopUpTopSend.this.badge_id.remove(0); PopUpTopSend.this.badge_id.add(0, selected_badge); } break; case 2: if(selected_badge!=badge_id.get(1)) { ivDrop = (ImageView) findViewById(R.id.ivBadgeSend2); imageLoader.DisplayImage(badge_url, ivDrop); PopUpTopSend.this.badge_id.remove(1); PopUpTopSend.this.badge_id.add(1, selected_badge); } break; case 3: if(selected_badge!=badge_id.get(2)) { ivDrop = (ImageView) findViewById(R.id.ivBadgeSend3); imageLoader.DisplayImage(badge_url, ivDrop); PopUpTopSend.this.badge_id.remove(2); PopUpTopSend.this.badge_id.add(2, selected_badge); } break; } llContainerDrag.removeView(ivDrag); PopUpTopSend.this.removeView(llContainerDrag); break; } } } </code></pre> <p>let's say I have 8 view to added dynamically so my code will add 2 view every loop from 1 and 2 until 7 and 8 but what passed to the cbDrag.onDrag is always 7th and 8th data so when I'm trying to drag the image will be shown is the 7th and 8th image, where I go wrong? is it when I'm trying to set the ontouch listener the data will always be changed because I have it in the loop?is there any way to solve this?</p> <p>thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload