每当单击edittext时,Recyclerview错误

时间:2019-06-06 18:13:32

标签: java android

我有一个recyclerviewcardviews组成。每个cardview都有一个EditTextTextView和两个图像按钮。如果我使用计算机的Android仿真器上的“标签”从一个edittext到下一个Cardview的编辑文本,那么一切都会正常进行。 但是,如果我直接从一个编辑文本单击到下一个,一切都会出错。前一个edittext中的文本消失,并成为我单击的edittext的文本。当前的edittext在空白和显示所传输的文本之间迅速切换,而我的logcat迅速并重复显示以下

W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection

这是ViewHolder

  public InputViewHolder(final View itemView) {
            super(itemView); 
            this.term = itemView.findViewById(R.id.edit_text); 
            focusChangeListener = new View.OnFocusChangeListener(){ 
                @Override 
                public void onFocusChange(final View v, boolean hasFocus) {
                    if (hasFocus) {
                        focusPosition = getAdapterPosition(); 
                     }
                    if(!hasFocus && focusPosition >= 0){
                        new Handler().post(new Runnable() {
                            @Override
                            public void run() {
                                if (focusPosition >= 0) {
                                    term = v.findViewById(R.id.edit_text);                                  
     allData.get(focusPosition).setText(term.getText().toString());

                                }

                            }
                        });
                    }
                }
            };
            term.setOnFocusChangeListener(focusChangeListener);
    }

这是onBindViewHolder

    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int 
    position) {
        Info current = allData.get(position);
        ((InputViewHolder) holder).term.clearFocus();
        ((InputViewHolder) holder).term.setText(current.getText());
        ((InputViewHolder) 
     holder).fraction.setText(((current.getFraction())));
     }

0 个答案:

没有答案