0

My ListView item consists of the following components - ImageView and then under it there are two more ImageViews - like and dislike.

So when I click on either like or dislike I want to be able to get corresponding ListView item id.

The only way that I am able to do it at the moment is if I first click on the ListView item and then on the like ImageView.

My question is - is there any way to get corresponding ListView item id without having to first click on the ListView item and only then on the like ImageView?

Here is my code

cursorAdapter = new PostCursorAdapter(this, null, 0);

        ListView list = (ListView)findViewById(android.R.id.list);
        list.setAdapter(cursorAdapter);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, final long l) {
                ivLike = (ImageView)findViewById(R.id.ivLike);

                ivLike.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        Log.d("Like","Like button for the post with id=" + l + " has been clicked");


                    }
                });
            }
        });

I was able to solve it myself. What I needed to do was to add setOnClickListener to my like and dislike ImageViews not in MainActivity but in PostCursorAdapter. Thanks everyone!

Nikolaj
  • 145
  • 3
  • 14

0 Answers0