Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:11:02+00:00 2026-06-05T15:11:02+00:00

I have been trying to create a ListView which I can sort using drag

  • 0

I have been trying to create a ListView which I can sort using drag and drop.

I have attempted to follow the Android guide here and some source code provided on Git over here. Also, I do not want to use the Music app example as I am trying to use the new tools given in Honeycomb and up.

So far I have been successful in creating the list and I can drag the items. Unfortunately when I drop the item onto the list I get the following error:

“I/ViewRoot(22739): Reporting drop result: false”.

I have a suspicion that my drop listener is not created on the right item and thus the drop never gets called. Here is some source code, thank you so much for your help.

XML For the List:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dropTarget"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:layout_weight="1">
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@android:id/list" >
    </ListView>
</LinearLayout>

My listView:
I have not yet been able to get into “ACTION_DROP” event so that code is not tested. Just something I was working on. My main question is that I never get into ACTION_DROP.

public class procedureListView extends ListActivity {
    private ListView mListView = null;
    private ArrayAdapter<String> mArrayAdapter = null;
    private View layoutDropArea = null;

    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.list);

          String[] countries = getResources().getStringArray(R.array.arrayOfStuff);
          mArrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, countries);
          setListAdapter(mArrayAdapter);

          mListView = getListView();
          mListView.setTextFilterEnabled(true);

          layoutDropArea = findViewById(R.id.dropTarget);

          setupDragDrop();
    }
    /**
     * Setup what to do when we drag list items
     */
    public void setupDragDrop(){
        mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> arg0, View v, int position, long arg3){
                String value = (String) ((TextView) v).getText();
                ClipData data = ClipData.newPlainText("procedure", value);
                v.startDrag(data, new mDragShadowBuilder(v), null, 0);          
                return true;
            }
        });
        myDragListener mDragListener = new myDragListener();
        //mListView.setOnDragListener(mDragListener);

        layoutDropArea.setOnDragListener(mDragListener);



    }
    protected class myDragListener implements OnDragListener{

        public boolean onDrag(View v, DragEvent event) {
            final int action = event.getAction();
            switch (action) {
                case DragEvent.ACTION_DRAG_ENTERED:
                    v.setBackgroundColor(Color.GRAY);
                    break;
                case DragEvent.ACTION_DRAG_EXITED:
                    v.setBackgroundColor(Color.TRANSPARENT);
                    break;
                case DragEvent.ACTION_DRAG_STARTED:
                    break;
                case DragEvent.ACTION_DRAG_LOCATION:
                    v.setVisibility(View.VISIBLE);
                // return processDragStarted(event);
                case DragEvent.ACTION_DROP:
                    v.setBackgroundColor(Color.TRANSPARENT);
                    int newPosition = mListView.getPositionForView(v);
                    if (newPosition != ListView.INVALID_POSITION)
                        return processDrop(event, newPosition);
                    else
                        return false;
            }
            return false;
        }

    }

    private boolean processDrop(DragEvent event, int newPosition) {
        ClipData data = event.getClipData();
        if (data != null) {
            if (data.getItemCount() > 0) {
                Item item = data.getItemAt(0);
                String value = item.toString();
                updateViewsAfterDropComplete(value, newPosition);
                return true;
            }
        }
        return false;
    }
    private void updateViewsAfterDropComplete(String listItem, int index) {
        Log.d("InsertItem", "Position: "+ index);
        mArrayAdapter.insert(listItem, index);
        mArrayAdapter.notifyDataSetChanged();
    }
    private boolean processDragStarted(DragEvent event) {
        ClipDescription clipDesc = event.getClipDescription();
        if (clipDesc != null) {
            return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
        }
        return false;
    }
}

Thank you so much for your help!

UPDATE:

I could not quite figure out why. But when I changed switch case to this, it seemed to work:

switch (action) {
                case DragEvent.ACTION_DRAG_ENTERED:
                    //v.setBackgroundColor(Color.GRAY);
                    return false;

                case DragEvent.ACTION_DRAG_EXITED:
                    //v.setBackgroundColor(Color.TRANSPARENT);
                    return true;

                case DragEvent.ACTION_DRAG_STARTED:
                    return true;

                case DragEvent.ACTION_DRAG_LOCATION:
                    //v.setVisibility(View.VISIBLE);
                    return false;
                // return processDragStarted(event);
                case DragEvent.ACTION_DROP:
                    v.setBackgroundColor(Color.TRANSPARENT);
                    int newPosition = mListView.pointToPosition((int)(event.getX()),(int) event.getY());
                    Log.d("Position", Integer.toString(newPosition));
                    if (newPosition != ListView.INVALID_POSITION)
                        return processDrop(event, newPosition);
                    else
                        return false;
                default:
                    return true;

            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:11:03+00:00Added an answer on June 5, 2026 at 3:11 pm

    Your update fixed the problem because you have to return true from onDrag when you get DragEvent.ACTION_DRAG_STARTED in order to continue receiving drag events to that listener. In your update you return true for this case, so you continue receiving drag events and the drop logic works correctly.

    If you don’t return true for the DragEvent.ACTION_DRAG_STARTED case, your listener won’t get any other events except DragEvent.ACTION_DRAG_ENDED.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a menu panel with jQuery that can be
I have been trying to create a simple program with Python which uses OpenCV
I have been trying to create an observable tweeter feed using tweetsharp with the
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php
I have been trying to find a good guide to create a templated control.
I have been trying to create a JFormattedTextField array which populates in a pane.
I have been trying to create a decorator that can be used with both
I have been trying to create rotating object using jQuery and without any other
I have been trying to create a page using views that will list down
I have been trying to create beta invites that each existing user can send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.