1

に画像を追加してListView表示することはできますが、リスト内のアイテムが 8 つを超えるListViewと、アイテムの間違った画像が表示されます。これが私のnewView()方法です:

public View newView(Context context, Cursor cursor, ViewGroup parent){
    final LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(layout, parent, false);
try{
        int count = cursor.getCount();
        String image = cursor.getString(cursor.getColumnIndex(RecipeClasses.Recipe.RECIPE_IMAGE));
        String recipe_name = cursor.getString(cursor.getColumnIndex(RecipeClasses.Recipe.RECIPE_NAME));

        Uri path = Uri.parse(image);
        TextView recipe_txt = (TextView) view.findViewById(R.id.txt_recipe_row);
        ImageView img = (ImageView) view.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 {
            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(recipe_name);
        }
    } catch (Exception e){
        // TODO: handle exception
    }

    return view;
}
4

2 に答える 2

2

あなたの newView は getView メソッドに似ていると思います。9番目のアイテムで取得したい画像が利用可能ですか?

Cursor を ArrayList に処理してみると、正確な問題を特定するために管理が容易になります。

また、指定されたパスにアイテムを割り当てようとすると、アイテムが正しくない可能性があるため、アイテムの新しく追加された画像のパス形式も確認してください。

于 2012-10-11T17:21:20.740 に答える
0

現時点での設定方法は、アダプターを実行するたびに新しいビューを拡張していることを意味します。これは、特に画像の場合、コストがかかります。

このチェックで初期ビューを再利用します。

View v;
if (view == null) {
    view = inflater.inflate(layout, parent, false);
}

このようにして、レイアウトは一度だけ膨張して再利用されます。

于 2012-10-11T16:08:08.827 に答える