Answer the question
In order to leave comments, you need to log in
How to access an imageview that is in a listview?
How to access an imageview that is in a listview?
I have 2 imageviews in my listview for each item. By clicking on the picture, I draw a rating on it. Do I need the imageview itself for this? i get Via tag
Get like this:
ImageView imgl= (ImageView) view.findViewById(R.id.imageLeft).findViewWithTag(pos);
tag
previous item except the last one
Answer the question
In order to leave comments, you need to log in
public static View getViewByPosition(int pos, ListView listView) {
final int firstListItemPosition = listView.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
if (pos < firstListItemPosition || pos > lastListItemPosition ) {
return listView.getAdapter().getView(pos, null, listView);
} else {
final int childIndex = pos - firstListItemPosition;
return listView.getChildAt(childIndex);
}
For example, when in the getView() method:
View getView(...) {
final ImageView image = ...;
otherImage.setOnClickListener(new View.OnClickListener(){
public void onClick(...){
//используем ссылку на image
}
}
...
}
image.setOnClickListener(new View.OnClickListener(){
public void onClick (View v){
ImageView image = (ImageView) v;
// работаем с этим же image
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question