Android 在列表视图中正确显示图像

Android 在列表视图中正确显示图像,android,listview,imageview,Android,Listview,Imageview,我有一个listview显示一个自定义行布局,显示一个Textview和两个EditText。 我在文本视图背景中显示图像,上面有文本。 在getView方法中,我异步加载图像并在listview中显示。 listview没有为不可见的行调用getview方法 当我滚动文本视图时,文本视图包含不同的图像,当它变得有些可见时,会得到实际图像。为什么会出现这种行为。请更新,因为我没有得到它 public View getView(int arg0, View arg1, ViewGroup arg

我有一个listview显示一个自定义行布局,显示一个Textview和两个EditText。 我在文本视图背景中显示图像,上面有文本。 在getView方法中,我异步加载图像并在listview中显示。 listview没有为不可见的行调用getview方法

当我滚动文本视图时,文本视图包含不同的图像,当它变得有些可见时,会得到实际图像。为什么会出现这种行为。请更新,因为我没有得到它

 public View getView(int arg0, View arg1, ViewGroup arg2) {
            // TODO Auto-generated method stub

            View v=arg1;

        EditText t1,t2;

            final TextView tv;
                       if (arg1 == null) 
               {  // if it's not recycled, initialize some attributes
                   LayoutInflater lf=(LayoutInflater)conn.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                   v=lf.inflate(R.layout.layitem,arg2,false);

               }

                   tv = (TextView)v.findViewById(R.id.textView1);
                   LinearLayout.LayoutParams ll=new LinearLayout.LayoutParams(width,width/2); // setting width to same as that of mobile screen
                   ll.setMargins(10, 0, 10, 0);

                    tv.setLayoutParams(ll);
                   // tv.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);


                    t1=(EditText)v.findViewById(R.id.editText1);
                    t2=(EditText)v.findViewById(R.id.editText2);

    // here count is actual no of rows that have image loaded from server rest will have default background    



               if(arg0<count)
               {
   Bitmap object=loadimage(iurl[arg0]);
          tv.setBackground(new BitmapDrawable(conn.getResources(),object));


              tv.setText(texts[arg0]);
              t1.setText(prays[arg0]);
             }
             else
             {
              tv.setBackgroundResource(R.drawable.wish);
              tv.setText("");
              t1.setText("0");
             }






               return v;
        }
公共视图getView(int arg0、视图arg1、视图组arg2){ //TODO自动生成的方法存根 视图v=arg1; 编辑文本t1,t2; 最终文本视图电视; 如果(arg1==null) {//如果没有回收,初始化一些属性 LayoutInflater lf=(LayoutInflater)conn.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE); v=左前充气(右布局放置项,arg2,假); } tv=(TextView)v.findViewById(R.id.textView1); LinearLayout.LayoutParams ll=新建LinearLayout.LayoutParams(宽度,宽度/2);//将宽度设置为与移动屏幕相同 ll.setMargins(10,0,10,0); tv.setLayoutParams(ll); //电视.设置重力(重力.重心水平|重力.重心垂直); t1=(EditText)v.findViewById(R.id.editText1); t2=(EditText)v.findViewById(R.id.editText2); //这里的计数是从服务器rest加载图像的行的实际数目,它将具有默认背景
if(arg0
ListView
在可见或将可见时将调用getView。而且在
getView
中,传递的参数
convertView
实际上是缓存视图(或
null
)。它可能是您以前创建的视图之一,因此它可能包含一些当前不可见的旧图像。

缓存视图是否为任何位置的任何视图都意味着视图。我们如何更正它以使图像更改的过渡不显示。请更新您可以在getView()的ImageView中设置虚拟图像方法。准备好后,您的异步映像将替换它。谢谢@Kuffs。但是我应该在哪里用异步映像替换它。在适配器中。您可以建议对此代码进行修改吗。映像正在从缓存中正确加载,但映像的转换仍在显示。看不到您的imageview在您发布的代码中的位置,但需要调用y一旦您膨胀了一个新视图或正在重用一个旧视图,就获取您的ImageView并在其中设置一个虚拟图像。