将ImageView设置为在自定义适配器内不可见

时间:2011-11-27 09:44:25

标签: android

我正在定义我自己的列表适配器,我希望它内部的图像显示或隐藏基于一个值,我注意到它始终不可见或可见而忽略该值

这是我的代码,这段代码在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);
             }

3 个答案:

答案 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); 
                    }