【发布时间】:2018-09-28 12:26:29
【问题描述】:
我在RecyclerView 项目中有一个EditText,一旦选择了该项目,我想显示键盘并专注于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"
/>
【问题讨论】:
标签: android android-recyclerview android-edittext setfocus