You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
}
The text was updated successfully, but these errors were encountered:
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);
}
public class RecyclerListAdapter extends RecyclerView.Adapter<RecyclerListAdapter.ItemViewHolder>
implements ItemTouchHelperAdapter {
The text was updated successfully, but these errors were encountered: