"Variable 'myDragListener' is never used"
hints that myDragListener
is either not inside the same Java class (in your case - your custom adapter), or is not accessible (for example if myDragListener
was declared public static
in another class, you would be able to access it).
To solve it, you'll have to make myDragListener
accessible, or instead, make your adapter implement View.OnDragListener
itself, like in the following example:
public class ImageAdapter extends BaseAdapter implements View.OnDragListener{ //Edited
Context context;
LayoutInflater inflater;
public MyAdapter(Context context) {
this.context = context;
inflater = LayoutInflater.from(context);
}
And the getView()
function:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_column, null);
viewHolder = new ViewHolder((ImageView) convertView.findViewById(R.id.ColPhoto));
convertView.setTag(viewHolder);
convertView.setOnDragListener(this); //Edited
} else
viewHolder = (ViewHolder) convertView.getTag();
viewHolder.iv.setImageBitmap((Bitmap) array.get(position).get(TAG_IMG));
viewHolder.position = position;
return convertView;
}
@Override
public boolean onDrag(View v, DragEvent event) {
Log.v("draglistener", "draglistener");
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
case DragEvent.ACTION_DRAG_ENTERED:
case DragEvent.ACTION_DRAG_EXITED:
case DragEvent.ACTION_DRAG_LOCATION:
case DragEvent.ACTION_DRAG_ENDED:
return true;
case DragEvent.ACTION_DROP:
//imageAdapter.addNewImage(v, event);
break;
default:
break;
}
return true;
}
Please note that instead of calling getSystemService
, it's preferable to pass Context as a parameter to the adapter's constructor, and then define the inflater once, via inflater = LayoutInflater.from(context)
.
Also note that the call .setOnDragListener()
requires API Level 11
and above.