我正在定义我自己的列表适配器,我希望它内部的图像显示或隐藏基于一个值,我注意到它始终不可见或可见而忽略该值
这是我的代码,这段代码在getView方法
中singleRow=data.get(position);
readit = singleRow.getRead();
Log.i("readit","" + readit );
//NotificationID=singleRow.getId();
holder.title.setText(singleRow.getAttach_title());
holder.date.setText( singleRow.getAttach_created());
holder.dueDate.setVisibility(ImageView.INVISIBLE);
holder.course.setText(singleRow.getCourse_title());
if(readit==1)
{
//holder.read.setImageResource(IGNORE_ITEM_VIEW_TYPE);
holder.read.setVisibility(ImageView.INVISIBLE);
}
else
{
holder.read.setImageResource(R.drawable.unread);
}
答案 0 :(得分:1)
holder.dueDate.setVisibility(View.GONE);
答案 1 :(得分:0)
将read
图片设置为VISIBLE
后,您永远不会将其设置回INVISIBLE
。在else
您可能应该setVisibility(VISIBLE)
答案 2 :(得分:0)
使用此代码。它将解决您的问题
singleRow=data.get(position);
readit = singleRow.getRead();
Log.i("readit","" + readit );
//NotificationID=singleRow.getId();
holder.title.setText(singleRow.getAttach_title());
holder.date.setText( singleRow.getAttach_created());
holder.dueDate.setVisibility(ImageView.INVISIBLE);
holder.course.setText(singleRow.getCourse_title());
holder.read.setImageResource(R.drawable.unread);
if(readit==1) {
//holder.read.setImageResource(IGNORE_ITEM_VIEW_TYPE);
holder.read.setVisibility(View.INVISIBLE);
}