【发布时间】:2012-12-26 11:58:09
【问题描述】:
我有一个列表视图,它显示来自互联网的图像和文本。 我的意图是这个图像,除了显示一个图像视图,是列表视图行的背景图像。 这可行,但有问题。
在我为图像视图准备的列表视图适配器中:
imageLoader.DisplayImage (song.get (principal.KEY_PICTURE) my_imageView);
并在 LinearLayout 中使用图像:
imageLoader.DisplayImageLinear (song.get (principal.KEY_PICTURE) my_linearLayout);
这会调用以下方法:
public void DisplayImageLinear (String url, LinearLayout linearbck)
{
Bitmap bitmap = memoryCache.get (url);
Drawable d = new BitmapDrawable (bitmap);
if (bitmap! = null) {
linearbck (d);
}
else
{ linearbck.setBackgroundResource (R.drawable.list_selector); }
}
我的问题是listview的行的背景图片只有在listview滑出屏幕并重新进入时才可见...
我希望我的解释正确..这里有一张解释问题的图片
我尝试使用linearbck.invalidate(),但是没有成功
我真诚地感谢任何帮助
谢谢
最好的问候
编辑:
添加适配器。谢谢:)
public class lstAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public MinAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);
ImageView photo_user =(ImageView)vi.findViewById(R.id.photoUser);
LinearLayout background =(LinearLayout)vi.findViewById(R.id.background);
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
imageLoader.DisplayImage(song.get(principal.KEY_AVATAR_AUTOR_ENTRADA), thumb_image);
imageLoader.DisplayImage(song.get(principal.KEY_PICTURE), photo_user);
imageLoader.DisplayImageLinear(song.get(principal.KEY_PICTURE), background);
return vi;
}
@Override
public boolean isEnabled(int position)
{
if(principal.asynTaskEnUso.equals("yes")){
return false;
} else {
return true;
}
}
}
【问题讨论】:
-
您可以粘贴适配器的代码吗?可能是您遗漏了与 convertview 相关的内容..
-
是的,发布更多细节的代码
-
当然,添加适配器。谢谢
标签: android listview bitmap drawable