2016-07-27 2 views
0

私のアプリケーション要件によると、リストビューのテキストボックス、イメージビュー、およびイメージキャプチャボタンを含む行が表示されています。私はイメージをキャプチャし、すぐにそのレルムの行にそのイメージを保存しています。アダプターのgetviewメソッドが呼び出されると、アダプターは関連するレルムオブジェクトからそのイメージをロードします。Realmbaseadapterのリストビュー項目イメージとテキストビューの再読み込み

私の問題は、各リストの行データが空白で4行以上あり、イメージをキャプチャしているときです。キャプチャされた画像は、その位置と一緒にいくつかの位置にロードされる。 たとえば、位置0の画像を撮影すると、位置5でスクロールした後に表示され、位置6に再び読み込まれます。位置0から位置6までスクロールした後、アダプタの位置が再び0を返すことに気付きました。他の位置でスクロールしている間にイメージが再読み込みされる理由はこれです。画像/テキスト入力のいずれかのボタンをクリックすると、このリロードされた行が再び適切な位置に戻ります。

私はリストビューでイメージビューシャッフルを発行することに関連するほとんどすべての可能な提案された質問を行ったが、どれも私のために働いていません。 マイアダプタのコードはここ

public class ProgressImageAdapter extends RealmBaseAdapter<ImageCommentRealm> implements ListAdapter { 
    private Context mContext; 
    String categoryName; 
    ProgressListener progressListener; 
    PopAlertDialog alertDialog; 
    boolean fromHistory; 

    public ProgressImageAdapter(Context context, OrderedRealmCollection<ImageCommentRealm> data, ProgressListener progressListener, boolean fromHistory) { 
     super(context, data); 
     this.mContext = context; 
     this.progressListener = progressListener; 
     FragmentActivity activity = (FragmentActivity) (context); 
     alertDialog = PopAlertDialog.createAlert(activity.getSupportFragmentManager()); 
     this.fromHistory = fromHistory; 
    } 

    @Override 
    public void updateData(OrderedRealmCollection<ImageCommentRealm> data) { 
     super.updateData(data); 
    } 

    public void resetListener() { 
     this.progressListener = null; 
    } 

    public void setCategoryName(String categoryName) { 
     this.categoryName = categoryName; 
    } 

    @Override 
    public void notifyDataSetChanged() { 
     super.notifyDataSetChanged(); 

    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     final ViewHolder holder; 
     if (convertView == null) { 
      convertView = inflater.inflate(R.layout.image_comment_list_item, parent, false); 
      holder = new ViewHolder(); 
      holder.textView = (TextView) convertView.findViewById(R.id.tv_title); 
      holder.editText = (TextView) convertView.findViewById(R.id.et_comment); 
      holder.imageView = (ImageView) convertView.findViewById(R.id.iv_camera_holder); 
      holder.imageButton = (ImageButton) convertView.findViewById(R.id.imgbtn_camera); 
      holder.btnDone = (Button) convertView.findViewById(R.id.btn_confirm); 
      convertView.setTag(holder); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 
     } 
     final ImageCommentRealm imageCommentRealm = getItem(position); 
     holder.textView.setText(String.format(Locale.getDefault(), "%s %d %2s %2s", mContext.getResources().getString(R.string.photo), position + 1, mContext.getString(R.string.of), categoryName)); 
     if (Validator.blankCheck(imageCommentRealm.getFile_path())) 
      loadImage(holder.imageView, imageCommentRealm.getFile_path()); 
     if (Validator.blankCheck(imageCommentRealm.getDesc())) 
      holder.editText.setText(imageCommentRealm.getDesc()); 
     if (!fromHistory) { 
      holder.imageButton.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        ((MainActivity) mContext).pickFromCamera(); 
        ((MainActivity) mContext).setPicker(new IPhotoPicker() { 
         @Override 
         public void setImageUri(String filePath) { 
          //loadImage(holder,filePath); 
          saveData(null, filePath, imageCommentRealm.getPk()); 

         } 
        }); 
       } 
      }); 
      holder.editText.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        String title = String.format(Locale.getDefault(), "%s %d %2s %2s", mContext.getResources().getString(R.string.description), position + 1, mContext.getString(R.string.of), categoryName); 
        alertDialog.showSingleInput(title, imageCommentRealm.getDesc(), imageCommentRealm.getPk(), new SingleInput.Listener() { 
         @Override 
         public void onClickGreen(String message, long id) { 
          if (Validator.blankCheck(message)) saveData(message, null, id); 
         } 
        }); 
       } 
      }); 
     } 
     return convertView; 
    } 

    protected void loadImage(ImageView imageView, String imgPath) { 
     if (imgPath.startsWith("http")) { 
      ImageUtility.loadProduct(mContext, imgPath, imageView, R.drawable.home); 
     } else { 
      try { 
       File image_file = new File(imgPath); 
       if (image_file.exists()) { 
        Bitmap image_profile = BitmapFactory.decodeFile(image_file.getAbsolutePath()); 
        imageView.setImageBitmap(image_profile); 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 


    private void saveData(final String comment, final String filepath, final long pk) { 
     final Realm realm = Realm.getInstance(RealmUtility.getRealmConfig(mContext)); 
     //ImageCommentRealm imageRealm = getItem(position); 
     //final long pk = imageRealm.getPk(); 
     realm.executeTransactionAsync(new Realm.Transaction() { 
      @Override 
      public void execute(Realm realm) { 
       ImageCommentRealm imageCommentRealm = realm.where(ImageCommentRealm.class).equalTo("pk", pk).findFirst(); 
       if (imageCommentRealm != null && imageCommentRealm.isLoaded()) { 
        if (Validator.blankCheck(comment)) { 
         imageCommentRealm.setDesc(comment); 
        } 
        if (Validator.blankCheck(filepath)) { 
         imageCommentRealm.setFile_path(filepath); 
        } 
       } 

      } 
     }, new Realm.Transaction.OnSuccess() { 
      @Override 
      public void onSuccess() { 

       //notifyDataSetChanged(); 
       realm.close(); 
       try { 
        if (adapterData != null && adapterData.size() > 0) { 
         long count = adapterData.where().isNotNull("file_path").isNotNull("desc").count(); 
         if (count == adapterData.size()) { 
          if (progressListener != null) progressListener.hasRequiredImage(); 
         } 
        } 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 
     }, new Realm.Transaction.OnError() { 
      @Override 
      public void onError(Throwable error) { 
       error.printStackTrace(); 
       realm.close(); 
      } 
     }); 
    } 

    static class ViewHolder { 
     TextView textView; 
     TextView editText; 
     ImageView imageView; 
     ImageButton imageButton; 
     Button btnDone; 
    } 
} 

below-である第一の位置での撮影した後、下 enter image description here

FYIにスクロールした後、スクリーンショットです:テストデバイス4" サムスンJ1 NXT

答えて

1

え、これはレルムとは関係ありません。画像パスがnullの場合は、画像を消去する必要があります。

if (Validator.blankCheck(imageCommentRealm.getFile_path())) { 
     loadImage(holder.imageView, imageCommentRealm.getFile_path()); 
    } else { 
     holder.imageView.setImageBitmap(null); 
    } 
    if (Validator.blankCheck(imageCommentRealm.getDesc())) 
     holder.editText.setText(imageCommentRealm.getDesc()); 
    } else { 
     holder.editText.setText(""); 
    } 
+0

ありがとうございました。問題。 – sbr1308

関連する問題