Last active
August 29, 2015 14:19
-
-
Save fatorx/3b35bdb115ad51dd8a12 to your computer and use it in GitHub Desktop.
Android RecyclerView - Adicionar um item
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addItem(int position, Object object) { | |
MessageUser message = (MessageUser) object; | |
messages.add(position, message); | |
notifyItemInserted(position); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Após setar o Adapter, e ter os dados carregados na RecyclerView | |
// Pegar o Adapter | |
// recyclerView foi setado com findViewById | |
YourAdapter adapter = (YourAdapter) recyclerView.getAdapter(); | |
// médoto getItemCount retorna o número atual de itens na lista | |
// parâmetro objectList é uma novo objeto para ser adicionado a lista | |
adapter.addItem(adapter.getItemCount(), objectList); | |
recyclerView.setAdapter(adapter); | |
recyclerView.refreshDrawableState(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment