當我嘗試每次使用回收的gridview時,如果convertView!= null,我得到一個錯誤,那麼我在這裏得到一個錯誤是我的源代碼。 它會給我一個錯誤,在text =(TextView)convertView;在其他語句中。我真的失去了這裏,我只想停止回收的意見,但隨後其沉重的記憶和波濤洶涌的滾動Android網格視圖回收問題
$這裏是imageadapter.java
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout lay;
ImageView image;
TextView text;
if (convertView == null) {
Log.d("height", "Width = " + width);
lay = new RelativeLayout(mContext);
image = new ImageView(mContext);
text = new TextView(mContext);
//text.setText("This is a test");
text.setTextSize(14);
text.setTextColor(Color.WHITE);
text.setGravity(Gravity.LEFT | Gravity.TOP);
text.setPadding(2, 2, 2, 2);
text.setBackgroundColor(Color.parseColor("#80000000"));
RelativeLayout.LayoutParams textLayout = new RelativeLayout.LayoutParams(
(int) Math.round(width/2.0),
(int) Math.round(width/8.3));
textLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
text.setLayoutParams(textLayout);
MarginLayoutParams textMarginFix = (ViewGroup.MarginLayoutParams) text
.getLayoutParams();
textMarginFix.setMargins(0, 0, 0, (int) Math.round(width/45.0));
text.setLayoutParams(textMarginFix);
image.setLayoutParams(new LayoutParams((int) Math
.round(width/2.0), (int) Math.round(width/ 2.0)));
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
//image.setImageResource(mThumbIds[position]);
lay.setLayoutParams(new GridView.LayoutParams((int) Math
.round(width/2.0), (int) Math.round(width/2.0)));
lay.setBackgroundResource(R.drawable.shadowimage);
lay.setPadding(5, 5, 15, 15);
//lay.setId(mThumbIds[position]);
//lay.addView(image);
//lay.addView(text);
}
else
{
text = (TextView) convertView;
image = (ImageView) convertView;
lay = (RelativeLayout) convertView;
}
image.setImageResource(mThumbIds[position]);
text.setText("This is a test");
lay.addView(image);
lay.addView(text);
return lay;
}
$here is where i call the imageadapter from another class
@Override
public Object instantiateItem(View container, int position) {
View contentView;
switch (position) {
case 0:
LayoutInflater mInflater = LayoutInflater.from(mContext);
View contentView = mInflater.inflate(R.layout.image_grid_view, null);
Display display = mContext.getWindowManager().getDefaultDisplay();
final int width = display.getWidth();
int height = display.getHeight();
float scale = mContext.getResources().getDisplayMetrics().density;
GridView gridview = (GridView) contentView.findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(mContext, width, height, scale));
gridview.setFocusable(true);
gridview.requestFocus();
gridview.setOnItemClickListener(itemClickListener);
((ViewPager) container).addView(contentView, 0);
break;
...return contentView
但我不是,這些圖像存儲在我看到的應用程序 – MobDev 2012-07-23 01:32:44
。我會建議按照答案重做代碼。 – sandrstar 2012-07-23 01:38:07