2011-11-27 93 views
0

我正在定義我自己的列表適配器,並且我希望顯示其中的圖像或基於值隱藏我已經注意到它始終不可見或可見的無視值將ImageView設置爲隱藏在自定義適配器內

這裏是我的代碼,這個代碼是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

還有一件事,我不能只用setImageResource(1),因爲它會搞亂了整個界面 –

回答

0

你永遠設置你read圖像回VISIBLE你一旦把它設置爲INVISIBLE后里面。在else你,或許,應該有setVisibility(VISIBLE)

+0

謝謝你的工作,但空間不見了,用戶界面搞砸了:( –

+0

你可以嘗試用GONE而不是INVISIBLE。用INVISIBLE,圖像變得不可見,但它佔據的地方仍然存在。它完全消失了,除此之外不能說沒有看到你的XML –

1
holder.dueDate.setVisibility(View.GONE); 
+0

你是什麼意思? –

+0

GONE將刪除該空間,整個UI將會混亂。我正在使用相對佈局 –

0

使用此code.It將解決您的問題

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); 
        } 
相關問題