I am having to create a database and display it later in a RecyclerView. I register my clients in one activity and show them in another. The problem is that when I register my clients, it does not immediately appear on the other activity, I have to close the App and open it again to update.
Here is my code:
package com.bancodedados.bancodedados;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.bancodedados.bancodedados.dominio.entidades.cliente;
import java.util.List;
/**
* Created by vande on 28/03/2018.
*/
public class ClienteAdapter extends RecyclerView.Adapter<ClienteAdapter.ViewHolderCliente>{
private List<cliente> dados;
public ClienteAdapter(List<cliente> dados){
this.dados = dados;
}
@Override
public ClienteAdapter.ViewHolderCliente onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.linha_clientes,parent,false);
ViewHolderCliente holderCliente = new ViewHolderCliente(view);
return holderCliente;
}
@Override
public void onBindViewHolder(ClienteAdapter.ViewHolderCliente holder, int position) {
if ((dados != null) && (dados.size()>0)) {
cliente Cliente = dados.get(position);
holder.txtNome.setText(Cliente.nome);
holder.txtTelefone.setText(Cliente.telefone);
}
}
@Override
public int getItemCount() {
return dados.size();
}
public class ViewHolderCliente extends RecyclerView.ViewHolder{
public TextView txtNome;
public TextView txtTelefone;
public ViewHolderCliente(View itemView) {
super(itemView);
txtNome = itemView.findViewById(R.id.txtNome);
txtTelefone = itemView.findViewById(R.id.txtTelefone);
}
}
}
If anyone can help me I would be grateful. I tried to use notifyDataSetChanged()
but could not.