Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag and Drop Between Two Recycle View

I have created 2 Horizontal recycleView. Which is working perfectly. I need the functionality of drag and drop between item inside each recycleView as well as drag and drop between those two recycleView's item. What I did still now -

private RecyclerView mRecyclerViewCompletedTask;
private RecyclerView.Adapter mAdapterCompletedTask;
private RecyclerView.LayoutManager mLayoutManagerCompletedTask;
private static String LOG_TAG = "RecyclerViewActivity";
private RecyclerView mRecyclerViewInCompleteTask;
private RecyclerView.Adapter mAdapterInCompleteTask;
private RecyclerView.LayoutManager mLayoutManagerInCompleteTask;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    mRecyclerViewCompletedTask = (RecyclerView) findViewById(R.id.my_recycler_view_completed_task);
    mRecyclerViewCompletedTask.setHasFixedSize(true);
    mLayoutManagerCompletedTask = new LinearLayoutManager(this);
    mRecyclerViewCompletedTask.setLayoutManager(mLayoutManagerCompletedTask);
    mAdapterCompletedTask = new MyRecyclerViewAdapterCompletedTask(getDataSet());
    mRecyclerViewCompletedTask.setAdapter(mAdapterCompletedTask);
    LinearLayoutManager layoutManager1 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mRecyclerViewCompletedTask.setLayoutManager(layoutManager1);

    mRecyclerViewInCompleteTask = (RecyclerView) findViewById(R.id.my_recycler_view_incomplete_task);
    mRecyclerViewInCompleteTask.setHasFixedSize(true);
    mLayoutManagerInCompleteTask = new LinearLayoutManager(this);
    mRecyclerViewInCompleteTask.setLayoutManager(mLayoutManagerInCompleteTask);
    mAdapterInCompleteTask = new MyRecyclerViewAdapterInCompleteTask(getDataSet());
    mRecyclerViewInCompleteTask.setAdapter(mAdapterInCompleteTask);
    LinearLayoutManager layoutManager2 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mRecyclerViewInCompleteTask.setLayoutManager(layoutManager2);
}

@Override
protected void onResume() {
    super.onResume();
    ((MyRecyclerViewAdapterCompletedTask) mAdapterCompletedTask).setOnItemClickListener(new MyRecyclerViewAdapterCompletedTask.MyClickListener() {
        @Override
        public void onItemClick(int position, View v) {
            Log.i(LOG_TAG, " Clicked on Item " + position);
        }
    });
    ((MyRecyclerViewAdapterInCompleteTask) mAdapterInCompleteTask).setOnItemClickListener(new MyRecyclerViewAdapterInCompleteTask.MyClickListener() {
        @Override
        public void onItemClick(int position, View v) {
            Log.i(LOG_TAG, " Clicked on Item " + position);
        }
    });
}

private ArrayList<DataObject> getDataSet() {
    ArrayList results = new ArrayList<DataObject>();
    for (int index = 0; index < 20; index++) {
        DataObject obj = new DataObject("Some Primary Text " + index,
                "Secondary " + index);
        results.add(index, obj);
    }
    return results;
}

Customised this library and got the things that I want. Link - https://github.com/woxblom/DragListView

like image 463
Anirban Avatar asked Nov 02 '15 02:11

Anirban


2 Answers

If you are still interested in a simple solution see my code on GitHub. It's shows how to Drag and Drop between two RecyclerViews.

like image 162
JuliaKo Avatar answered Oct 10 '22 18:10

JuliaKo


Customised this library and got the things that I want. Link - https://github.com/woxblom/DragListView

What I updated -

As you can see it's a vertical recyclerView use layout manager so that you can make it Gird or Horizontal recylerView. In my case I have 2 recyclerView and 1 GridView. Also adjusted some padding and layout.

like image 31
Anirban Avatar answered Oct 10 '22 17:10

Anirban