Skip to content

Instantly share code, notes, and snippets.

@zerogdev
Last active July 19, 2018 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerogdev/471bf98546a675b91c877f8c2e38359b to your computer and use it in GitHub Desktop.
Save zerogdev/471bf98546a675b91c877f8c2e38359b to your computer and use it in GitHub Desktop.
RecyclerView recyclerView = findViewById(R.id.recyclerview);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setItemAnimator(null);
final ArrayList<String> items = new ArrayList<>();
items.add("hello~ item1");
items.add("hello~ item2");
items.add("hello~ item3");
final RecyclerAdapter adapter = new RecyclerAdapter(items);
recyclerView.setAdapter(adapter);
findViewById(R.id.last_item_favorite_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//refresh last item
adapter.notifyItemChanged(adapter.getItemCount() - 1, "click");
}
});
findViewById(R.id.all_item_favorite_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//refresh all item
adapter.notifyItemRangeChanged(0,adapter.getItemCount(), "click");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment