Change data from a specific position in Listview

Asked

Viewed 419 times

4

I would like to know how I can change data from a certain Listview position.

Here I upload from the database to Listview:

public void carregarEmails(Cliente cliente) {
    ArrayList<Email> listaView = dao.pegarResultListaEmail(cliente);
    listaEmail.setAdapter(new ClienteCadEmailBaseAdapter(getActivity(), listaView));
}

Code retrieving data from selected line:

private void informacaoSelecionadaEmail(View v) {
    listaEmail = (ListView) v.findViewById(R.id.lstEmails);
    listaEmail.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Object o = listaEmail.getItemAtPosition(position);
            objEmail = (Email) o;
            posicaoEmail = position;
            edtEmail.setText(objEmail.getEmail());
        }
    });
}

Now to take the changed in Edittext and send to the line again that I have no idea how to do.

  • 1

    Welcome to Sopt. It would be nice to add the code of your attempts so that we can help you better =]

  • Hello, thank you very much, so I have no idea how to change, I can recover by getItemAtPosition, but to return the value changed to the position I have no idea how it does, I already researched something that could help me but I believe I’m looking for wrong

  • So put in your current code and we’ll help you

  • added the bank capture and capture codes from Listview

1 answer

2


To Listview is a visual representation of the data from a data source.
The data is converted into Views using a Adapter

Thus, to change any given/value shown by Listview, it is necessary to amend that data source and inform the Adapter of that change, using the Adapter.notifyDataSetChanged().

  • Hello ramaral, if I understood after the change I use the novityDataSetChanged() method, I read some things about but could not understand, this method serves to persist the data inside the Adapter?

  • I have now seen the addition to the question. If you are using a BD you should use a Cursoradapter. If you want to continue using Basedapter you will need to make the change to ArrayList<Email> listaView and in the comic book and then call notifyDataSetChange(). The notifyDataSetChange does not persist at all, just informs the Adapter to update the Listview.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.