Reputation: 31
My GridView
at the start of activity look like correct
but after scrolling down and up items position changes
my last item in first row has a big text, I think this is my issue
this is my getView()
code
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null) {
LayoutInflater li = getLayoutInflater();
v= li.inflate(R.layout.item, null);
} else {
v= convertView;
}
ImageView imageView = (ImageView) v.findViewById(R.id.grid_item_image);
imageView.setImageResource(R.drawable.logo);
TextView textView = (TextView) v.findViewById(R.id.grid_item_label);
textView.setText(PersianReshape.reshape( Values[position].getName()));
Typeface face = Typeface.createFromAsset(context.getAssets(),"font/BNazanin.ttf");
textView.setTypeface(face);
textView.setTextSize(farin.code.rahnamee.attrib.attribute.content_font_size);
return gridView;
}
Upvotes: 0
Views: 1704
Reputation: 62411
You should change your getView method like this.
public View getView(int position, View convertView, ViewGroup parent){
// TODO Auto-generated method stub
View v;
if(convertView==null)
{
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.icontext, null);
}else{
v = convertView;
}
TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setText(providers[position]);
ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.setImageResource(R.drawable.icon);
return v;
}
Your problem is that when you use convertView it stores old data form the first records. Convert view is used to avoid layout inflation from resource which costs you time and memory. You should use the old inflated view, but set new data.
Upvotes: 0
Reputation: 28932
Your grid items should all have a uniform height. Consider setting a min/max number of lines of text to ensure uniform height, and ensure that the ImageView
has a consistent size as well. One way would be to use a known, fixed size for the ImageView
rather than simply wrap_content
.
Upvotes: 1