1

読み込まれた画像を画面に表示できる場合、ListView は正しく動作しているようです。しかし、画像のない新しいアイテムを追加すると、そのアイテムが表示されなくなり、ListView はそのアイテムの画像をロードし続けます。カスタム アレイアダプターを使用しています。

 int resource;
        private RecipeClasses mRecipeClass;
        private Recipe mRecipe;
        private Context context;
        Uri path;

    public RecipeAdapter(Context context, int _resource, List<Recipebag> items)
    {
        super(context, _resource, items);
        resource = _resource;
        mRecipeClass = new RecipeClasses(context);
        this.context = context;
        mRecipe = new Recipe(context);
    }

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

        LinearLayout newView;
        Recipebag item = getItem(position);
        long id = item.getRecId();
        mRecipeClass.open();
        Cursor recipe = mRecipe.setCursorToRecipe(id);
        String name = recipe.getString(recipe.getColumnIndexOrThrow(RecipeClasses.Recipe.RECIPE_NAME));
        String image = recipe.getString(recipe.getColumnIndexOrThrow(RecipeClasses.Recipe.RECIPE_IMAGE));
        mRecipeClass.close();
        String newId = String.valueOf(id);
        if(image== null)
        {
            image = " ";
        }
        else
        {
             path = Uri.parse(image);
        }

        if (convertView == null)
        {
            // Inflate a new view if this is not an update.
            newView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater li;
            li = (LayoutInflater) getContext().getSystemService(inflater);
            li.inflate(resource, newView, true);
        }
        else
        {
            // Otherwise we’ll update the existing View
            newView = (LinearLayout) convertView;
        }
        TextView recipe_txt = (TextView) newView.findViewById(R.id.txt_recipe_row);
        ImageView img = (ImageView) newView.findViewById(R.id.img_view_recipe);
        if(new File(image).exists())
        {
        ImageResizer img_W = new ImageResizer(context, img.getMeasuredWidth(), img.getMeasuredHeight());
        img_W.loadImage(image, img);
        }
        else if(image!= " ")

        {
            ImageResizer img_W = new ImageResizer(context, img.getMeasuredWidth(), img.getMeasuredHeight());
            img_W.loadImage(path, img);
            img.setImageURI(path);
        }
        if (recipe_txt != null)
        {
            recipe_txt.setText(name);
        }
        return newView;
    }
4

2 に答える 2

0

私が知る限り、ImageViewinのコンテンツをクリアすることは決してありませんgetView()。したがって、行がリサイクルされると、すでにイメージがあります。画像がない場合を処理する必要がありますgetView()-試しsetImageDrawable(null)てみてください。

于 2012-10-13T12:45:18.227 に答える
0

画像がない場合にのみ対応する必要があります。つまり、レシピ画像を更新するまでの間、デフォルトの画像を表示します。

これを試して

if(image != null)
{ 
   icon.setImageBitmap(image); 
    return; 
} 

アイコンは ImageView になります

設定したイメージは、プロジェクト リソースにある場合は既定のイメージ (R.id.default) になります。または、必要なシステム リソース イメージをプロジェクトにコピーし、そこから呼び出します。

于 2012-10-13T13:10:14.593 に答える