0

I am trying to add and remove edittext through RecyclerView Adapter and it's working fine but I also want to shift the focus to next empty edittext when I click on adapter item which fills the edit text. It would be grateful if someone could help ,I am newbie to android.

  1. Here is my focus next method:
private void focusNext() {
        View view = getAdapterView(mAddDropPointAdapter.getCurrentFocusedPosition() + 1);
        }
        if (view != null) {
            view.findViewById(R.id.fragment_google_autoc_et_destination).requestFocus();
        } else if (getActivity() != null) {
            KeyboardUtils.hideKeyboard(getActivity());
        }
    }

  1. Here is from where I am calling this method.
@Override
    public void onAdapterItemClick(int position, @NonNull GoogleAutoCompleteAddressDto addressDto) {

/// Doing some stuff

 focusNext();
}

After clicking the adapter item , focus stays at the same edittext it doesn't shift to next.

pandey_shubham
  • 363
  • 4
  • 14
  • is it multiline edittext? – lvl4fi4 Jun 24 '19 at 06:29
  • No , it's single line edit text . – pandey_shubham Jun 24 '19 at 06:31
  • check this answer https://stackoverflow.com/questions/17989733/move-to-another-edittext-when-soft-keyboard-next-is-clicked-on-android – lvl4fi4 Jun 24 '19 at 06:34
  • Thanks @lvl4fi4, but it's not helpful as I don't have id of next edit text as it's adding dynamically. – pandey_shubham Jun 24 '19 at 06:44
  • `View viewItem = recycleView.getLayoutManager().findViewByPosition(position); EditText next = viewItem.findViewById(R.id.edittext);` and call requestfocus on it – lvl4fi4 Jun 24 '19 at 06:47
  • this is what I am already doing @Nullable private View getAdapterView(int position) { if (vRecyclerView.getLayoutManager() != null) { return vRecyclerView.getLayoutManager().findViewByPosition(position); } return null; } – pandey_shubham Jun 24 '19 at 07:35

0 Answers0