Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I tried it. ,but ...something wrong #38

Open
Bob-liuboyu opened this issue Mar 20, 2016 · 2 comments
Open

I tried it. ,but ...something wrong #38

Bob-liuboyu opened this issue Mar 20, 2016 · 2 comments

Comments

@Bob-liuboyu
Copy link

when I deleted a item and scrolling screen,something wrong。。。。,I am a chinese boy, my English....

you can use those code ,try it,you will see it,thank you very much

public class MainActivity extends Activity {
private RecyclerView mRecyclerView;
private ItemTouchHelper mItemTouchHelper;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    RecyclerListAdapter adapter = new RecyclerListAdapter(this);
    mRecyclerView = (RecyclerView) findViewById(R.id.mRecyclerView);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);
}

}

public class RecyclerListAdapter extends RecyclerView.Adapter<RecyclerListAdapter.ItemViewHolder>
implements ItemTouchHelperAdapter {

private final List<String> mItems = new ArrayList<>();


public RecyclerListAdapter(Context context) {
    mItems.addAll(Arrays.asList(context.getResources().getStringArray(R.array.dummy_items)));
}

@Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main, parent, false);
    return new ItemViewHolder(view);
}

@Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
    holder.textView.setText(mItems.get(position));
}

@Override
public void onItemDismiss(int position) {
    mItems.remove(position);
    notifyItemRemoved(position);
}

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    Collections.swap(mItems, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    return true;
}

@Override
public int getItemCount() {
    return mItems.size();
}

/**
 * Simple example of a view holder that implements {@link ItemTouchHelperViewHolder} and has a
 * "handle" view that initiates a drag event when touched.
 */
public static class ItemViewHolder extends RecyclerView.ViewHolder {

    public final TextView textView;
    public final ImageView handleView;

    public ItemViewHolder(View itemView) {
        super(itemView);
        textView = (TextView) itemView.findViewById(R.id.text);
        handleView = (ImageView) itemView.findViewById(R.id.handle);
    }
}
@maninwindow
Copy link

@Bob-liuboyu I tried it too, it is running smoothly. What is your problem? Please paste the error message.

@Bob-liuboyu
Copy link
Author

Happy to receive your mail,you can watch the video,you will see,

------------------ 原始邮件 ------------------
发件人: "Alimjan";[email protected];
发送时间: 2016年3月24日(星期四) 晚上6:01
收件人: "iPaulPro/Android-ItemTouchHelper-Demo"[email protected];
抄送: "伯羽君"[email protected];
主题: Re: [Android-ItemTouchHelper-Demo] I tried it. ,but ...somethingwrong (#38)

@Bob-liuboyu I tried it too, it is running smoothly. What is your problem? Please paste the error message.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants