Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get item from listView onItemClick in android?

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

like image 346
Brucode Avatar asked Dec 15 '22 11:12

Brucode


1 Answers

Simple as that. parent.getItemAtPosition(position);

like image 146
Mateus Brandao Avatar answered Jan 19 '23 08:01

Mateus Brandao