wasabeef / recyclerview-animators

An Android Animation library which easily add itemanimator to RecyclerView items.
Apache License 2.0
11.49k stars 1.98k forks source link

i can't use this library #52

Open tellfa opened 8 years ago

tellfa commented 8 years ago

i want use this library but i can't use :( . i added this code : compile 'jp.wasabeef:recyclerview-animators:1.3.0' and added this code to my activity : mRecyclerView = (RecyclerView) findViewById(R.id.profile_user_recycler);

    mRecyclerView.setItemAnimator(new SlideInUpAnimator(new OvershootInterpolator(1f)));
    mRecyclerView.getItemAnimator().setAddDuration(1000);
    mRecyclerView.getItemAnimator().setRemoveDuration(1000);
    mRecyclerView.getItemAnimator().setMoveDuration(1000);
    mRecyclerView.getItemAnimator().setChangeDuration(1000);

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new profile_user_adapter(myDataset);
    mRecyclerView.setAdapter(mAdapter);

please help me, i really need this library. tnx <3

aesean commented 8 years ago

try notifyItemInserted(index); notifyItemRemoved(index);

aesean commented 8 years ago

Don't use notifyDataSetChanged();

tellfa commented 8 years ago

@aesean tnx, Where do I add the code? It is possible to guide me further?

aesean commented 8 years ago

mRecyclerView.setAdapter(mAdapter); mAdapter class

tellfa commented 8 years ago

@aesean , my adapter code : public class profile_user_adapter extends RecyclerView.Adapter { private static String[] mDataset;

public profile_user_adapter(String[] myDataset) {
    mDataset = myDataset;
}
@Override
public profile_user_adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
            R.layout.newsms_card_layout, null);
    ViewHolder viewHolder = new ViewHolder(itemLayoutView);return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
    viewHolder.tvVersionName.setText(mDataset[position].toString());
}
@Override
public int getItemCount() {
    return mDataset.length;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
    public TextView tvVersionName;
    public ViewHolder(View itemLayoutView) {
        super(itemLayoutView);
        tvVersionName = (TextView) itemLayoutView.findViewById(R.id.sms_newsms_text);
        itemLayoutView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }
}

}

if possible you add this methods too my adapter? tnx <3

aesean commented 8 years ago

public class profile_user_adapter extends RecyclerView.Adapter { private List < String > mDataset; public profile_user_adapter(List < String > myDataset){ this.mDataset =myDataset; }

public void insertItem(String item){
    insertItem(item, mDataset.size());
}

public void insertItem(String item,int index){
    mDataset.add(item);
    notifyItemInserted(index);
}

public void removeItem(String item,int index){
    mDataset.remove(index);
    notifyItemRemoved(index);
}

@Override
public profile_user_adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
            R.layout.newsms_card_layout, null);
    ViewHolder viewHolder = new ViewHolder(itemLayoutView);
    return viewHolder;
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {

}

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

public static class ViewHolder extends RecyclerView.ViewHolder {
    public TextView tvVersionName;

    public ViewHolder(View itemLayoutView) {
        super(itemLayoutView);
        tvVersionName = (TextView) itemLayoutView.findViewById(R.id.sms_newsms_text);
        itemLayoutView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }
}

}

tellfa commented 8 years ago

@aesean , tnx man <3

wasabeef commented 8 years ago

Please use the following
notifyItemChanged(int) notifyItemInserted(int) notifyItemRemoved(int) notifyItemRangeChanged(int, int) notifyItemRangeInserted(int, int) notifyItemRangeRemoved(int, int)

If you want your animations to work, do not rely on calling notifyDataSetChanged(); as it is the RecyclerView's default behavior, animations are not triggered to start inside this method.