2011-02-07 59 views
0

我正在定製(充氣)列表視圖。其中我使用了文本和背景圖像(根據條件)。 現在我面臨着滾動列表視圖的問題,即文本視圖的背景與其他文本視圖重疊。 下面是示例代碼:在充氣列表視圖中的問題

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

View icontextlayout=convertView; 
    icontextlayout= inflater.inflate(R.layout.layout_complex_list, null); 
    TextView Txt1=(TextView)icontextlayout.findViewById(R.id.txt1); 
if(disp1==true) 
{ 
Txt1.setBackgroundResource(R.drawable.pic) 
} 
    else 
Txt1.setText("Text1 "+strUser);// 

    TextView Txt2=(TextView)icontextlayout.findViewById(R.id.txt2); 
if(disp2==true) 
{ 
Txt2.setBackgroundResource(R.drawable.pic); 
} 
    else Txt2.setText("Text2: "+strIndus); 
return icontextlayout;  

}

能否請你幫我出這個背景圖像Pic不重疊的其他背景。

感謝你......

回答

1

的問題是,你必須設置一個默認的背景,當你不需要的背景。例如:

if(disp1==true){ 
    Txt1.setBackgroundResource(R.drawable.pic); 
    Txt1.setText(""); 
} 
else{ 
    Txt1.setText("Text1 "+strUser);// 
    Txt1.setBackgroundDrawable(null); 
} 

另外,如果你不介意的話,我想給你我的意見對你的代碼:


View icontextlayout=convertView; 
icontextlayout= inflater.inflate(R.layout.layout_complex_list, null); 

,這是不好的,因爲你沒有實際使用convertView(當你調用inflater.inflate),它會創建一個新的行,從而你的名單會很慢。

  • if(disp2==true)是多餘的。你應該考慮使用:if(disp2)
+0

它工作。你真的贏得我的關注。謝謝Cristian。 – Pankaj 2011-02-07 14:00:00