0

내 arraylist가 어댑터와 연결되어있는 recyclerview를 호출했습니다. 그리고 어댑터가 자신의 행 파일을 가지고있을 때 하나의 편집 텍스트를 찍었고 수동으로 그 양을 입력 할 수 있습니다.Android에서 recyclerview를 스크롤 할 때 편집 문구 값이 사라짐

그러나 문제는 내가 recyclerview를 스크롤 할 때 편집 텍스트 값이 사라졌습니다. 그래서 어느 쪽이든 나를 입력 한 값을 볼 수 없습니다.

어댑터 클래스

public class AddSecondarySalesOrderProductDetailsAdapter extends RecyclerView.Adapter { 

    ArrayList<SecondarySalesProductDetailsModel> mArrSecondarySalesProductDetailsModel; 
    ArrayList<String> mArrProductQuantity; 
    private int mViewItem = 1; 
    private Activity mActivity; 
    private LayoutInflater mLayoutInflater; 
    ImageView mImageDeleteProduct; 
    private String mProductName, mProductAvaQuantity, mProductSKU, mOrderedQuantity; 

    /** 
    * Adapter contains the data to be displayed 
    */ 
    public AddSecondarySalesOrderProductDetailsAdapter(Activity mActivity, ArrayList<SecondarySalesProductDetailsModel> 
      mArrSecondarySalesProductDetailsModel) { 
     this.mActivity = mActivity; 
     this.mArrSecondarySalesProductDetailsModel = mArrSecondarySalesProductDetailsModel; 
     mArrProductQuantity = new ArrayList<>(); 
     mLayoutInflater = LayoutInflater.from(mActivity); 
    } 

    @Override 
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View view = mLayoutInflater.inflate(R.layout.raw_add_secondary_sales_order_product_details, parent, 
       false); 
     return new CustomViewHolder(view); 
    } 

    @Override 
    public int getItemViewType(int position) { 
     return mArrSecondarySalesProductDetailsModel.get(position) != null ? mViewItem : 0; 
    } 

    @Override 
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) { 
     holder.setIsRecyclable(false); 
     final SecondarySalesProductDetailsModel mAllProductDetailsModel = mArrSecondarySalesProductDetailsModel.get(position); 
     ((CustomViewHolder) holder).mImageDeleteProduct.setTag(position); 

     mProductName = mAllProductDetailsModel.getProductName(); 
     mProductAvaQuantity = String.valueOf(mAllProductDetailsModel.getAvalQty()); 
     mProductSKU = mAllProductDetailsModel.getSku(); 

     ((CustomViewHolder) holder).mTextProductName.setText(mProductName); 
     ((CustomViewHolder) holder).mTextProductAvaQuantity.setText(mProductAvaQuantity); 
     ((CustomViewHolder) holder).mTextProductSKU.setText(mProductSKU); 

     ((CustomViewHolder) holder).mImageDeleteProduct.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       mArrSecondarySalesProductDetailsModel.remove(position); 
       notifyItemRemoved(position); 
       notifyItemRangeChanged(position, mArrSecondarySalesProductDetailsModel.size()); 

       if (mArrSecondarySalesProductDetailsModel.size() == 0) { 
        AddSecondarySalesOrderProductDetailFragment.mRelativeNoRecords.setVisibility(View.VISIBLE); 
       } 
      } 
     }); 
     OrderedQuantityTextWatcher textWatcher = new OrderedQuantityTextWatcher(holder, ((CustomViewHolder) holder).mEditOrderedQuantity, position); 
     ((CustomViewHolder) holder).mEditOrderedQuantity.addTextChangedListener(textWatcher); 
     ((CustomViewHolder) holder).mEditOrderedQuantity.setTag(position); 
    } 

    private class OrderedQuantityTextWatcher implements TextWatcher { 
     private EditText editText; 
     private int position; 
     private RecyclerView.ViewHolder holder; 

     public OrderedQuantityTextWatcher(RecyclerView.ViewHolder holder, EditText editText, int 
       pos) { 
      this.holder = holder; 
      this.editText = editText; 
      this.position = pos; 
     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
//   mOrderedQuantity = mEditOrderedQuantity.getText().toString().trim(); 
     } 

     @Override 
     public void afterTextChanged(Editable editable) { 
//   int position = holder.getAdapterPosition(); 
      int position = (int) editText.getTag(); 

      Common.insertLog("Position: " + position); 
      Common.insertLog("Value: " + editable); 

      SecondarySalesProductDetailsModel secondarySalesProductDetailsModel = new 
        SecondarySalesProductDetailsModel(); 
      secondarySalesProductDetailsModel.setId(mArrSecondarySalesProductDetailsModel.get(position).getId()); 
      secondarySalesProductDetailsModel.setProductName 
        (mArrSecondarySalesProductDetailsModel.get(position).getProductName()); 
      secondarySalesProductDetailsModel.setAvalQty(mArrSecondarySalesProductDetailsModel 
        .get(position).getAvalQty()); 
      secondarySalesProductDetailsModel.setOrderedQty(editable.toString().trim()); 
      secondarySalesProductDetailsModel.setSku(mArrSecondarySalesProductDetailsModel.get 
        (position).getSku()); 
      secondarySalesProductDetailsModel.setProductId(mArrSecondarySalesProductDetailsModel 
        .get(position).getProductId()); 
      secondarySalesProductDetailsModel.setSelected(mArrSecondarySalesProductDetailsModel 
        .get(position).getSelected()); 
//   mArrSecondarySalesProductDetailsModel.add(secondarySalesProductDetailsModel); 

      Intent intent = new Intent(AppConstants.BROADCAST_SEND_SECONDARY_PRODUCTS); 
      intent.putExtra(AppConstants.BUNDLE_BROADCAST_ORDERED_QUANTITY, 
        secondarySalesProductDetailsModel); 
      LocalBroadcastManager.getInstance(mActivity).sendBroadcast(intent); 
     } 
    } 

    @Override 
    public int getItemCount() { 
     return mArrSecondarySalesProductDetailsModel.size(); 
    } 

    /** 
    * Initialization of components 
    */ 
    public class CustomViewHolder extends RecyclerView.ViewHolder { 

     TextView mTextProductName, mTextProductAvaQuantity, mTextProductSKU; 
     EditText mEditOrderedQuantity; 
     ImageView mImageDeleteProduct; 

     public CustomViewHolder(final View itemView) { 
      super(itemView); 
      this.mImageDeleteProduct = (ImageView) itemView.findViewById(R.id 
        .image_raw_secondary_sales_order_delete); 
      this.mTextProductName = (TextView) itemView.findViewById(R.id.text_raw_secondary_sales_order_product_name); 
      this.mTextProductAvaQuantity = (TextView) itemView.findViewById(R.id 
        .text_raw_secondary_sales_order_ava_quantity); 
      this.mTextProductSKU = (TextView) itemView.findViewById(R.id 
        .text_raw_secondary_sales_order_product_sku); 
      this.mEditOrderedQuantity = (EditText) itemView.findViewById(R.id 
        .edit_raw_secondary_sales_order_quantity); 
     } 
    } 

답변

0

내가 모델 클래스 너무 객체 텍스트 변경 업데이트에 대한 onBindViewHolder (텍스트를 편집하도록 설정 한 번 더 필드와 객체 생성에 비어 설정을) 만들 .. 귀하의 EditText 값이 recyclerview에게

솔루션을 스크롤에 0 인 경우 :

0

문제 다음 텍스 내부에 EDITTEXT에 코드 아래 사용 twatcher 메서드 afterTextchange()

Code : yourEditTextName.setSelection(yourEditTextName.getText().length());  
관련 문제