Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

android - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...