第二个EditText在android中没有获得Request focus

时间:2017-02-08 08:47:59

标签: android android-fragments android-edittext

我有两个EditText,并希望当文本计数变为11时,它会跳转到另一个EditText。我想将此过程重构为另一个名为UIHelper的类,并调用该方法并传递第一个和第二个EditText和视图,然后执行此操作。 这就是我所做的一切:

UIHelper.class中的

  public static void NextFocous( int et1, int et2,int size, View view){
        ed_size=size;

            edit1 = (EditText) view.findViewById(et1);
            edit2 = (EditText) view.findViewById(et2);

        edit1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                int char_count=s.length();
                Log.d("char1", String.valueOf(char_count));
                if(char_count==ed_size) {

                    edit2.requestFocus();

                    Log.d("char1", "if executed");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

并在片段中将其称为:

public class _step5_Fragment_Payment extends Fragment implements View.OnClickListener{


    public _step5_Fragment_Payment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.frag_menu_step5_payment, container, false);
UIHelper.NextFocous(R.id.drug_username,R.id.drug_password,11,view);
  return view;
    }
}

0 个答案:

没有答案