public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) { Toast toast = Toast.makeText(getApplicationContext(), position, Toast.LENGTH_SHORT); toast.show(); } 

Position is the number (position of the element), I need to display text from the element. enter image description here

Ie when clicking I need to display the text which is highlighted in bold in the listView

  • When I click on an item, I need to output the text from that element. - Romag
  • Added more descriptions. - Romag

1 answer 1

 TextView textView = (TextView)itemClicked.findViewById(R.id.textView); String text = textView.getText().toString+(); 

itemClicked is an itemClicked view, it also comes in the onItemClick method. From it we are looking for everything you want by id and use

at the insistence of @pavlofff and conscience

Get the data unit.

 Object click = adapter.getItem(position); String first = click.getFirst(); String second = click.getSecond(); 

There are no methods getFirst() and getSecond() , I just made it clear that you need to take data from a data model, for example, or something else. I do not know the data structure. If not clear, put the adapter code

  • one
    Carrying data from the view is not a very reasonable solution. The adapter has a getItem() method that will return the unit of data for which the View filled - pavlofff
  • one
    I know, but he will not understand. - Flippy
  • 2
    This is not a reason for substandard answers, explain so that understand. Moreover, you answer not the person who personally asked the question, but publish the correct solution to the problem. - pavlofff