我有一个recyclelerview,显示两种不同类型的viewholder,在一种类型中我有一个Edit Text字段,当手机处于纵向状态时键盘工作正常,但是当它处于横向状态时我无法输入,当我触摸输入的编辑文本时,它会闪烁键盘并滚动到我列表的最后一个位置,而在log cat中我得到了#34;无效的inputConnection"警告。它只发生在手机上,当我在平板电脑上测试它工作正常。 有人可以帮帮我吗?
使用编辑文本查看持有人
public static class ViewHolderBack extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private int qtd;
private Button btnBack;
private Button btnAddCart;
private Button btnSubCart;
private EditText etQuantity;
private TextView tvSubTotal;
private TextView tvTest;
public ViewHolderBack(View itemView) {
super(itemView);
qtd = 1;
btnBack = (Button) itemView.findViewById(R.id.btn_back_front);
btnBack.setOnClickListener(this);
btnAddCart = (Button) itemView.findViewById(R.id.btn_add_cart);
btnAddCart.setOnClickListener(this);
btnAddCart.setOnLongClickListener(this);
btnSubCart = (Button) itemView.findViewById(R.id.btn_sub_cart);
btnSubCart.setOnClickListener(this);
btnSubCart.setOnLongClickListener(this);
etQuantity = (EditText) itemView.findViewById(R.id.tv_quantity);
tvSubTotal = (TextView) itemView.findViewById(R.id.tv_subtotal);
tvTest = (TextView) itemView.findViewById(R.id.tv_card_back);
etQuantity.setText(String.valueOf(qtd));
etQuantity.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (s.length() != 0) {
if (Integer.parseInt(s.toString()) < 2) {
btnSubCart.setEnabled(false);
} else {
btnSubCart.setEnabled(true);
}
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() != 0) {
qtd = Integer.parseInt(s.toString());
if (Integer.parseInt(s.toString()) < 2) {
btnSubCart.setEnabled(false);
} else {
btnSubCart.setEnabled(true);
}
} else {
qtd = 0;
etQuantity.setText("0");
}
tvSubTotal.setText(String.format("Total: R$ %.2f", dataset.get(getPosition()).getPrice() * qtd));
}
});
if (qtd == 1) {
btnSubCart.setEnabled(false);
}
}
public TextView getTvTest() {
return this.tvTest;
}
public int getQtd() {
return this.qtd;
}
public TextView getTvSubTotal() {
return tvSubTotal;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_back_front:
IntesigMobileApplication.SELECTED.delete(getPosition());
OrderProductCustomAdapter.adapter.notifyItemChanged(getPosition());
break;
case R.id.btn_add_cart:
qtd = Integer.parseInt(etQuantity.getText().toString());
qtd++;
if (qtd > 1) {
btnSubCart.setEnabled(true);
}
etQuantity.setText(String.valueOf(qtd));
tvSubTotal.setText(String.format("Total: R$ %.2f", dataset.get(getPosition()).getPrice() * qtd));
hideSoftKeyboard(v);
break;
case R.id.btn_sub_cart:
qtd = Integer.parseInt(etQuantity.getText().toString());
qtd--;
if (qtd == 1) {
btnSubCart.setEnabled(false);
}
etQuantity.setText(String.valueOf(qtd));
tvSubTotal.setText(String.format("Total: R$ %.2f", dataset.get(getPosition()).getPrice() * qtd));
hideSoftKeyboard(v);
break;
}
}
我的适配器 `public class OrderFragment扩展了Fragment {
private static final String TAG = "OrderFragment";
private static final String KEY_LAYOUT_MANAGER = "layoutManager";
private static final String KEY_SPAN_COUNT = "spanCount";
private static int SPAN_COUNT = 3;
protected enum LayoutManagerType {
STAGGERED_GRID_MANAGER, LINEAR_LAYOUT_MANAGER
}
protected LayoutManagerType lmtCurrentLayoutManagerType;
protected RecyclerView recyclerView;
protected OrderProductCustomAdapter orderProductCustomAdapter;
protected RecyclerView.LayoutManager rvlayoutManager;
protected List<DummyContent.DummyProduct> mDataset;
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @return A new instance of fragment OrderFragment.
*/
public static OrderFragment newInstance() {
OrderFragment fragment = new OrderFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public OrderFragment() {
// Required empty public constructor
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
assert ((AppCompatActivity) getActivity()).getSupportActionBar() != null;
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.title_orders);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initDataset();
}
private void initDataset() {
this.mDataset = IntesigMobileApplication.PRODUCTS;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);
rootView.findViewById(R.id.fab).setVisibility(View.GONE);
rootView.setTag(TAG);
//Initialize recycler view
recyclerView = (RecyclerView) rootView.findViewById(R.id.my_recyclerview);
if (savedInstanceState != null) {
// Restore saved layout manager type.
lmtCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState
.getSerializable(KEY_LAYOUT_MANAGER);
if (lmtCurrentLayoutManagerType == LayoutManagerType.STAGGERED_GRID_MANAGER)
SPAN_COUNT = savedInstanceState.getInt(KEY_SPAN_COUNT);
}
orderProductCustomAdapter = new OrderProductCustomAdapter(mDataset);
recyclerView.swapAdapter(orderProductCustomAdapter, false);
recyclerView.setItemAnimator(new CardFlipAnimator(this.getContext()));
recyclerView.getItemAnimator().setSupportsChangeAnimations(true);
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
SPAN_COUNT = 3;
setRecyclerViewLayoutManager(LayoutManagerType.STAGGERED_GRID_MANAGER);
} else {
SPAN_COUNT = 2;
setRecyclerViewLayoutManager(LayoutManagerType.STAGGERED_GRID_MANAGER);
}
} else {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
SPAN_COUNT = 2;
setRecyclerViewLayoutManager(LayoutManagerType.STAGGERED_GRID_MANAGER);
} else {
setRecyclerViewLayoutManager(LayoutManagerType.LINEAR_LAYOUT_MANAGER);
}
}
return rootView;
}
public void setRecyclerViewLayoutManager(LayoutManagerType layoutManagerType) {
int scrollPosition = 0;
int[] positions = new int[]{-1, -1, -1};
switch (layoutManagerType) {
case STAGGERED_GRID_MANAGER:
rvlayoutManager = new StaggeredGridLayoutManager(SPAN_COUNT, StaggeredGridLayoutManager.VERTICAL);
lmtCurrentLayoutManagerType = LayoutManagerType.STAGGERED_GRID_MANAGER;
break;
case LINEAR_LAYOUT_MANAGER:
default:
rvlayoutManager = new LinearLayoutManager(getActivity());
lmtCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
break;
}
if (recyclerView.getLayoutManager() != null) {
if (((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) ||
(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
scrollPosition = ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPositions(positions)[0];
} else {
scrollPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
}
}
recyclerView.setLayoutManager(rvlayoutManager);
recyclerView.scrollToPosition(scrollPosition);
}`