在Gallery和LinearLayout之间切换-ClassCastException
|
谢谢阅读!
我正在构建一个自定义Gallery应用程序,其中第一个缩略图是显示专辑详细信息的专辑封面。流程如下:
getView() {
//inflate cover.xml which includes two textviews and an imageview.
if(position == 0)
//set some album-specific text
else
//set image-specific text
}
这是实际的getView()代码:
public View getView(int position, View convertView, ViewGroup parent) {
//TODO: Recycle view
convertView = mInflater.inflate(R.layout.cover, null);
TextView tvTxt1 = (TextView)convertView.findViewById(R.cover.tvCoverText1);
TextView tvTxt2 = (TextView)convertView.findViewById(R.cover.tvCoverText2);
//ImageView imgView = (ImageView)convertView.findViewById(R.cover.imgImage);
if(position == 0) {
tvTxt1.setText(\"AlbumText1\");
tvTxt2.setText(\"AlbumText2\");
return convertView;
}
else {
tvTxt1.setText(\"ImageText1\");
tvTxt2.setText(\"ImageText2\");
ImageView imgView = new ImageView(mContext);
imgView.setImageResource(mImageIds[position]);
imgView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(mGalleryItemBackground);
return imgView;
//return convertView;
}
}
cover.xml
包含an3ѭ和两个TextView
。
当我在else
块中返回convertView
时,我得到了ClassCastException。我当然做错了。
我现在已经花了将近两天时间:(
请帮忙!
没有找到相关结果
已邀请:
3 个回复
锑寝粒
结乳
bab
这是我的布局
文件:
Main.java中的其余代码(我修改了
方法)从此处几乎逐字记录 再次感谢您的帮助!