How to get item from listView onItemClick in android?

Brucode  picture Brucode · Sep 30, 2015 · Viewed 14.5k times · Source

I'm working on an app and in that app I've created a custom listview. I am populating the listView from an API call.Now on the click of a perticular list item i want to get the data which is shown on that index. What shall i change in the below code

  vehicle_select_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            ImageView selectedImage = (ImageView) view.findViewById(R.id.checkBox);

           selectedImage.setImageResource(R.drawable.simplecheck);
           String str =  parent.getAdapter().getItem(position).toString();

            Toast.makeText(getApplicationContext(), "  " + str , Toast.LENGTH_SHORT).show();
        }
    });
}

Please help. Thank you

Answer

Mateus Brandao picture Mateus Brandao · Sep 30, 2015

Simple as that. parent.getItemAtPosition(position);