2012-04-25 27 views
0
I made a sample using this link: http://ericharlow.blogspot.in/2010/10/experience-android-drag-and-drop-list.html. 
i am able to drag and drop objects from my list view. 

Here is the code for my start and stop drag: 


public void onStartDrag(View itemView) { 
      itemView.setVisibility(View.INVISIBLE); 
      defaultBackgroundColor = itemView.getDrawingCacheBackgroundColor(); 
      // itemView.setBackgroundColor(backgroundColor); 
      mChangeButton = (Button) findViewById(R.id.change_btn); 
      Button iv = (Button) itemView.findViewById(R.id.delete_btn); 
      if (iv != null) 
       iv.setVisibility(View.INVISIBLE); 
     } 

     @Override 
     public void onStopDrag(View itemView) { 
      itemView.setVisibility(View.VISIBLE); 
      // itemView.setBackgroundColor(defaultBackgroundColor); 
      mChangeButton = (Button) findViewById(R.id.change_btn); 
      Button iv = (Button) itemView.findViewById(R.id.delete_btn); 
      if (iv != null) 
       iv.setVisibility(View.VISIBLE); 
     } 

我的問題是我怎麼能爲我的按鈕iv設置OnClickListener? 它不允許我在onDrag上設置。 在此先感謝Android:如何設置onClickListener方法聲明組件在開始和停止拖動

+0

你嘗試setonclicklistener? – blessenm 2012-04-25 10:38:55

回答

0

1)創建一個監聽對象 2)創建這就需要定義監聽器 3)內部阻力一套監聽 的方法什麼錯誤你當這可能工作:)

OnClickListner onclicklistner; 
..... 
void listner() 
{ 
onclicklistner=new OnclickListner({ 
void onClick(v.getid){...} 
}); 
} 
.... 
button.setoOnClickListener(onclicklistener);` 
相關問題