質問

I am trying to create some kind of memory app for learning words for different languages.

So far I have created the layout with TextViews and Buttons and the buttons are draggable - can be long pressed and dragged.

Now I would like to make it possible to swap buttons' when you drag one button on another but I have noticed so far that buttons cannot have onDragListener because I get the following error:

The method setOnDragListener(View.OnDragListener) in the type View is not applicable for the arguments (new OnDragListener(){})

So far my code looks like this

for (final Button b : buttonList) {
  //b.setOnDragListener(new MyDragListener());

  b.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
       ClipData.Item item = new ClipData.Item( ((Button) v).getText() );

       String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
       ClipData dragData = new ClipData(
           ((Button) v).getText().toString(), 
           mimeTypes, 
           item);

       // Instantiates the drag shadow builder.
       View.DragShadowBuilder myShadow = new DragShadowBuilder(b);

       // Starts the drag
       v.startDrag(dragData,  // the data to be dragged
                   myShadow,  // the drag shadow builder
                   null,      // no need to use local data
                   0          // flags (not currently used, set to 0)
       );
       return true;
    }
 });

  // Create and set the drag event listener for the View
  b.setOnDragListener( new OnDragListener(){
     // ....
  }
}
役に立ちましたか?

解決

You're missing an import statement.

import View.OnDragListener;

or

.setOnDragListener(new View.OnDragListener()

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top