0

나는 recyclerview에서 편집 텍스트 편집을 마쳤을 때 notifydatasetchanged를하려고합니다 (이유는? recyclerview의 다른 객체는 액세스 할 수있는 경우에만 텍스트 편집은 "테스트"와 같습니다).안드로이드 - editify를 편집 할 때 notifyDataSetChanged

public EditTextViewHolder(View itemView, final Activity activity, final Context context, final String param) { 
    super(itemView); 

    this.activity = activity; 
    this.context = context; 
    this.param  = param; 


    name  = (TextView) itemView.findViewById(R.id.tEditTextName); 
    desc  = (TextView) itemView.findViewById(R.id.tEditTextDescription); 
    details  = (TextView) itemView.findViewById(R.id.tEditTextMoreDetails); 
    editText = (EditText) itemView.findViewById(R.id.eEditTextValue); 
    image  = (ImageView) itemView.findViewById(R.id.iEditTextImage); 
    lMain  = (LinearLayout) itemView.findViewById(R.id.layoutTaskEditText); 
    lOptional = (LinearLayout) itemView.findViewById(R.id.layoutEditTextOptional); 
    lRequired = (LinearLayout) itemView.findViewById(R.id.isRequiredTask); 

} 

public void setLayout(final Content content) { 
    name.setText(content.getTitle()); 

editText.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      content.getAnswers().get(0).setValue(s.toString().trim()); 
     } 
    }); 

    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View v, boolean hasFocus) { 
      if (!hasFocus) 
       TaskActivity.sAdapter.notifyDataSetChanged(); 
     } 
    }); 
} 

그러나 "RecyclerView은 레이아웃을 계산하거나 스크롤하는 동안이 방법을 호출 할 수 없습니다"나는 오류가 받고 있어요 : 그래서

내가 여기에 편집 텍스트의 하나입니다, 많은 뷰 홀더와 어댑터를 가지고 핸들러 나 UI 스레드에서 통지하려고해도 작동하지 않습니다.

내 모든 다른보기 소유자와 함께 작동합니다. 편집 텍스트로 내가 뭘 잘못하고 있는지 아십니까?

답변

0

활동 대신 어댑터에서 notifyDataSetChanged를 호출하고 UIThread에서 내부 호출을 시도하십시오.

activity.runOnUiThread(new Runnable() { 

             @Override 
             public void run() { 

             } 
            }); 

및 어댑터 내부에 있는지 확인하십시오, 당신은 notifyItemInserted (위치); notifyItemChanged (위치)를 호출 할 때이 예외가 아마 발생하는 데이터

@Override 
    public int getItemCount() { 
    } 
+0

이봐, 내가 확인하기 위해 다시 한 번이 솔루션을 시도했지만 그것은 확실히 난 아직 RecyclerView 동안이 방법을 호출 할 수 없습니다 "가 작동하지 않습니다 레이아웃 또는 스크롤링을 계산하는 것입니다. " 나는 다른 파일에 많은 뷰 홀더를 가지고 있는데, 그 이유는 어댑터가 정적 인 액티비티로 내 어댑터를 얻는 이유입니다. –

+0

더 많은 코드를 게시 할 수 있습니까? 또한 당신은 setLayout 메쏘드를 어디에서 호출 할까? –

+0

어댑터의 onbind 함수에서 setLayout (이름이 적절하지 않을 수 있음)이 호출됩니다. 나 또한 uset getItemType –

0

오른쪽 번호를이 방법을 가지고 또는 notifyItemRemoved (위치); 백그라운드 스레드에서 (또는 백그라운드 스레드에서 실행되는 콜백). 이 문제를 해결하기 위해

, UI 스레드에서 Handler를 사용

android.os.Handler mHandler = getActivity().getWindow().getDecorView().getHandler(); 
mHandler.post(new Runnable() { 
    public void run(){ 
      //change adapter contents 
      mRecyclerViewAdapter.notifyItemInserted(position); 
    } 
}); 
+0

이봐, 나는이 솔루션을 다시 한 번 시도했지만, 응용 프로그램이 충돌하지는 않지만 edittext가 포커스를 잃을 때 텍스트는 사라진다. 편집 텍스트에 글을 쓰고있을 때 객체의 내용을 확인했는데 잘 복사되었습니다. 또는 내가 편집하고 텍스트를 다른 편집 텍스트로 전환 할 때 recyclerview (텍스트 편집)에서 같은 객체를 두 번 사용하면 ... –