У меня есть 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"
/>