0

I am working on customize (inflated) list view. In which I have used the text and background image for text (as per the condition). Now I am facing problem in scrolling the list view that background of text view is overlapping to the other text views. Here is the sample code:

@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;      

}

Could you please help me out that background image pic do not overlap the others background.

Thanking you...

Pankaj
  • 833
  • 12
  • 35

1 Answers1

1

The problem is that you must set a default background when you don't need a background. For instance:

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

Also, if you don't mind, I like to give you my opinion about your code:


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

Which is bad, because you are not actually using the convertView (when you call inflater.inflate) it will create a new row, thus your list will be really slow.

  • if(disp2==true) is redundant. You should consider using just: if(disp2).
Community
  • 1
  • 1
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • Really thanks for options too, I understand and the code was only to easily understand that which type of values are. Anyways you helped. – Pankaj Feb 07 '11 at 14:02