如何在Adapter Android中再次刷新动画相同的视图

时间:2019-06-10 10:08:13

标签: android xml android-recyclerview recycler-adapter

在单击项目时,适配器应刷新,并应再次调用onCreateViewHolder和onBindViewHolder,以便刷新数据和动画。

每次列表更新时,我都希望从右到左制作recyclerview动画(无论何时调用notifydatasetchanged)我的列表正在更新,但动画没有发生

 public myAdapter(Context context, RecyclerView recyclerview_songs){
   this.context = context;
   this.recyclerview_songs = recyclerview_songs;
 }


 @Override  
  public SongListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, 
 int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.row_songlist, parent, false);
      return new SongListViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull final SongListViewHolder holder, 
final int position) {
  startAnimation(circle);
  if(!array_first.isEmpty()) {
      count =1;
      holder.text_name.setText(array_first.get(position).getTitle());
   }
 if(array_first.isEmpty() && array_second.size() > 0) {
      count =2;
      holder.text_name.setText(array_second.get(position).getTitle());
   }

holder.text_name.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          if(count ==1){
             array_first.clear();
             stopAnimation();
          }
          notifyDataSetChanged();
     }
  });
}

     public void startAnimation() {
    int animid = R.anim.animatefromright;
    LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(context, animid);
    recyclerview_songs.setLayoutAnimation(controller);
}

0 个答案:

没有答案