I've been trying to re-set the size of an ImageView. I'm using a custom adapter.
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.grid_item, null);
}
thumb = (ImageView) row.findViewById(R.id.bookThumb);
When I use ImageView thumb = (ImageView) row.findViewById(R.id.bookThumb); inside the custom adapter it works great but because it's looping through every row it makes the scrolling very slow.
So... I'm now trying to get the thumb = (ImageView) row.findViewById(R.id.bookThumb); from my Main Activity and set its size but I get Null and therefore the app force closes.
Tried:
LinearLayout layout = (LinearLayout) findViewById(R.id.gridLayout);
ImageView thumbRow = (ImageView)layout.findViewById(R.id.bookThumb);
Also tried:
// gv is the gridview (R.id.gridview)
ImageView thumbRow = (ImageView)gv.findViewById(R.id.bookThumb);
Always get null.
Appreciate any help! feels like I'm missing something silly :)
hierarchyviewer
to see what actually your view hierarchy looks like. – CollusiveR.id.bookThumb
. If some branch of the view hierarchy contains many elements with the same id, and you callfindViewById()
from the root of that branch, it will return null because it doesn't know which one you want. – SharpfreezeImageView
(when adding them) the sameLayoutParams
object, then modify that object and call arequestLayout()
on the gridview? – Sharpfreeze