开发者社区> 问答> 正文

GridView 无法显示文字:配置报错 

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder viewHolder = null;

Kindergarten entity = list.get(position);

if (convertView != null && convertView.getId() == R.id.teacher_list) {

viewHolder = (ViewHolder) convertView.getTag();

} else {

viewHolder = new ViewHolder();

convertView = mInflater.inflate(R.layout.childavatar, null);

// int pHight = mgridView.getHeight();

//        GridView.LayoutParams params = new GridView.LayoutParams(

//                        LayoutParams.MATCH_PARENT, pHight / 3);

//       

AbsListView.LayoutParams param = new AbsListView.LayoutParams(

               android.view.ViewGroup.LayoutParams.FILL_PARENT,

               mgridView.getHeight()/3);

viewHolder.text_name = (TextView) convertView

.findViewById(R.id.childname);

viewHolder.imageIcon = (ImageView) convertView

.findViewById(R.id.childhead);

Resources r = Resources.getSystem();

            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, r.getDisplayMetrics());

            Log.i("px", px+"");

            convertView.setLayoutParams(param);

         //  viewHolder.imageIcon.setLayoutParams(new LinearLayout.LayoutParams((int)px, (int)px));

         //  viewHolder.imageIcon.setScaleType(ImageView.ScaleType.FIT_XY);

// viewHolder.parent_name1=(TextView)convertView.findViewById(R.id.parent1);

// viewHolder.parent_name2=(TextView)convertView.findViewById(R.id.parent2);

}

if(entity.getChildeavatar()!=null){

String tag = AppConfig.IMAGE_FILE+ entity.getChildeavatar();

if (tag.contains("?")) {// 截断?后的字符串,避免无效图片

tag = tag.substring(0, tag.indexOf("?"));

}

viewHolder.imageIcon.setTag(tag);

Drawable cachedImage = asyncImageLoader.loadDrawable(

ImageCacher.EnumImageType.Avatar, tag, new ImageCallback() {

public void imageLoaded(Drawable imageDrawable, String tag) {

Log.i("Drawable IN teacherAdapter", tag);

ImageView imageViewByTag = (ImageView) mgridView

.findViewWithTag(tag);

if (imageViewByTag != null && imageDrawable != null) {

imageViewByTag.setImageDrawable(imageDrawable);

} else {

try {

imageViewByTag

.setImageResource(R.drawable.jiazhangtouxiang);

} catch (Exception ex) {

}

}

}

});

if (cachedImage != null) {

viewHolder.imageIcon.setImageDrawable(cachedImage);

Log.i("setImg in method Check in", tag+"??");

}

else {

viewHolder.imageIcon.setBackgroundResource(R.drawable.jiazhangtouxiang);

Log.i("setImg in method Check in  else", tag+"??");

}

}

viewHolder.text_name.setText(entity.getClassName());

Log.i("ChildName", entity.getClassName());

convertView.setTag(viewHolder);

return convertView;

展开
收起
kun坤 2020-06-04 10:23:27 495 0
1 条回答
写回答
取消 提交回答
  • 自己顶一下,无法显示文字啊! 我已经 viewHolder.text_name.setText(entity.getClassName()); 了 而且,如果 去掉这句   convertView.setLayoutParams(param);  就又显示文字了! 崩溃了~但是我必须控制它显示的高度 确保全屏铺满啊!

    2020-06-04 11:19:36
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载