我有一个recyclerview
由cardviews
组成。每个cardview
都有一个EditText
,TextView
和两个图像按钮。如果我使用计算机的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())));
}