我在EditText
项中有一个RecyclerView
,选择该项后,我想显示键盘并将焦点对准EditText
,但是我什么也不做。
我使用CarouselView库,该库与RecyclerView相同。
活动中:
listStudent.setOnItemSelectedListener(new CarouselView.OnItemSelectedListener() {
@Override
public void onItemSelected(CarouselView carouselView, int position, int adapterPosition, RecyclerView.Adapter adapter) {
try {
View view = listStudent.getLayoutManager().findViewByPosition(listStudent.getCurrentAdapterPosition());
final EditText ed = ButterKnife.findById(view, R.id.edScore);
ed.requestFocus();
ed.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager)
AppController.Context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(ed, InputMethodManager.SHOW_IMPLICIT);
}});
} catch (Exception ex) {}
}
@Override
public void onItemDeselected(CarouselView carouselView, int position, int adapterPosition, RecyclerView.Adapter adapter) {
}
});
在XML子项中
<EditText
android:id="@+id/edScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@xml/layout_border_color_primary"
android:digits="0123456789."
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:lines="1"
android:maxLength="5"
/>
答案 0 :(得分:0)
只需在您的try块内添加
ed.setFocusableInTouchMode(true);