麻烦膨胀的ListView [英] Trouble in inflated listview

查看:142
本文介绍了麻烦膨胀的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的定制(充气)列表视图。在我所用文本的文本和背景图像(根据条件)。
现在我在滚动列表视图文本视图的背景重叠其他文本视图面临的问题。
下面是示例code:

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.

感谢你...

推荐答案

的问题是,您必须设置一个默认的背景,当你不需要的背景。例如:

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

另外,如果你不介意的话,我想给你关于你的code我认为:

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


  • 这不是他们的方式通常填充列表。看看这个答案:<一href=\"http://stackoverflow.com/questions/1320478/how-to-load-the-listview-smoothly-in-android/1321565#1321565\">How加载列表视图顺利,在机器人

  • convertView 用于重用行。在你的情况,你正在做的事情,如:

  • That's not they way in which list are usually populated. Take a look at this answer: How to load the Listview "smoothly" in android
  • convertView is used to reuse rows. In your case you are doing something like:
View icontextlayout=convertView;
icontextlayout= inflater.inflate(R.layout.layout_complex_list, null);


,这是不好的,因为你没有实际使用 convertView (当你调用 inflater.inflate ),它将创建一个新的行,因此你的名单将是非常缓慢的。


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.


  • 如果(DISP2 == true)而是多余的。您应该考虑使用刚:如果(DISP2)

  • if(disp2==true) is redundant. You should consider using just: if(disp2).

这篇关于麻烦膨胀的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆