不要在 CarouselView 内的 EditText 上应用 requestFocus

Do not apply requestFocus on EditText that is inside CarouselView

我在 RecyclerView 项目中有一个 EditText ,一旦选择该项目,我想显示键盘并聚焦在 EditText 上,但我没有这样做任何东西。

我用的是CarouselView库,和RecyclerView是一样的

在Activity中:

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"
            />

只需在您的 try 块中添加即可

ed.setFocusableInTouchMode(true);