1
Talk guys, I’m new on android, I have a problem here, I’m trying to insert items in a Recyclerview, when I use the direct method on the button it is inserting statically good:
public void listenersButtons() {
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Cria uma nova pessoa
ModelContato pessoa1 = new ModelContato();
pessoa1.setNome("Felipe");
//Adiciona a pessoa1 e avisa o adapter que o conteúdo
//da lista foi alterado
pessoasListas.add(pessoa1);
adapter.notifyDataSetChanged();
}
});
}
But now I need to evolve, I want that when click on that same button open a screen with a form and a save button, there I capture the dice and play back to the main.
I’m doing like this:
public void listenersButtons() {
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(PrincipalActivity.this, Contato.class);
startActivity(it);
finish();
}
});
}
And from there returns the Strings and I’m trying to insert in Recyclerview like this:
@Override
protected void onResume() {
super.onResume();
Intent itt = getIntent();
if (itt != null){
Bundle parametro = itt.getExtras();
if (parametro != null){
ModelContato pessoa1 = new ModelContato();
if (parametro.getString("nome") != pessoa1.getNome()) {
String nome = parametro.getString("nome");
String email = parametro.getString("email");
String num = parametro.getString("num");
pessoa1.setNome(nome);
pessoa1.setEmail(email);
pessoa1.setNumero(num);
pessoasListas.add(pessoa1);
adapter.notifyDataSetChanged();
}
}
}
}
The problem is that now when I return it fills the recycleview correctly with the values I filled in the form, only when doing the process again it replaces, that is, it always stays only 1 item in my list.
I put inside onResume for trial and error, I also tested on onCreate and the same thing happens.
Another detail is that when browsing the application, when I go on another Activity and go back to the main a new item is added, same as the previous one, I tried to fix this with the last if of Cod on onResume, but it didn’t work.
No mistake, but it doesn’t work the way I need it.
Thanks in advance, vlw!
Thanks for the stuff.
– lmart