how to pass an item from a listview to a textview in the same Activity

Asked

Viewed 39 times

0

My question is regarding the capture of information in a ListView on Android and paste the same information into a TextView.

Example: I created a ListView fruit and I want to click on a fruit from the list the name of this fruit appears in this TextView.

  • 1

    do you have any code already done? could put it in question? is in java or Kotlin?

2 answers

1

Try it like this:

seuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { itemSelecionado = lista.get(i); seuTextView.setText(itemSelecionado); return false; } });

This "list", is the list that is populating your ListView (List, Arraylist, etc)

I hope I’ve helped

0

mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            //aqui vc irá fazer a acao com o click pegando uma posicao da sua lista, e setando o texto
            mText = mListaFrutas[position]; 
        }
    });

Browser other questions tagged

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