0

I have a listview and what I want is when I click on listView row, the Imageview which I have used in ListView row changes to different drawable. Here is the code what I have tried.

lvAdminData.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent,
                    View convertView, int position, long id) {
                @SuppressWarnings("unused")
                RelativeLayout rel=(RelativeLayout) adapter.getView(position, null,null);
                ImageView arrowView=(ImageView) rel.getChildAt(2);
                arrowView.setImageResource(R.drawable.info_details_navigation_white);
                            }
        });
    }

Here is the snapshot:

This white should turn into blue on click of row

2
  • 1
    what is the problem exactly? Commented Nov 21, 2013 at 11:20
  • I want that anywhere on this row I click and this arrow image change. Commented Nov 21, 2013 at 11:27

4 Answers 4

1

Try this..

lvAdminData.setOnItemClickListener(new AdapterView.OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> parent,View convertView, int position, long id)  {    

        ImageView arrowView=(ImageView) convertView.findViewById(R.id.yourid);  //replace with your ImageView id
        arrowView.setImageResource(R.drawable.info_details_navigation_white);
        }
});
Sign up to request clarification or add additional context in comments.

Comments

0

Try

rel.invalidate() ; 

after

arrowView.setImageResource(R.drawable.info_details_navigation_white);

Comments

0

Solved: I have directly found id of imageview . Now its working.

lvAdminData
        .setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent,
                    View convertView, int position, long id) {

                ImageView arrowView=(ImageView) convertView.findViewById(R.id.imageViewArrow);
                arrowView.setImageResource(R.drawable.info_details_navigation);
                onAdminItemClick(parent, position);
            }
        });

1 Comment

try using more items, so that you have to scroll and see if it still works, when you scroll up and down.
0

try this in

lvAdminData.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent,View convertView, int position, long id)  {    

    ImageView arrowView=(ImageView) convertView.findViewById(R.id.imageid);  
    arrowView.setImageResource(R.drawable.info_details_navigation_white);
    }

});

2 Comments

Your code will work when we will click on Image but I want wherever One click on row , It should change.
try with convertView.setOnClickListner and see

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.