Check click position on a Listview

Asked

Viewed 135 times

4

I have a screen that has a ListView inside it, I need to identify which line was clicked to direct to the correct location. How can I do this?

1 answer

5


You can use the method setOnItemClickListener() in this way:

listItemView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, listItemsValue[position], Toast.LENGTH_SHORT).show();
            }
        });

In my case it results in a message Toast onscreen:

inserir a descrição da imagem aqui

Details

Good luck.

  • I can make an IF inside the setOnItemClickListener?

  • @carlosgiovanicasilo yes, always.

  • Thank you so much for your help.

Browser other questions tagged

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