AqsaSarwar:
私は2つのEditTextビュー(ユーザ名とパスワード)をしました、私は両方のフィールドが空の場合は第一のEditTextに注力したいとユーザ名がすでに入力された場合には、[パスワード]フィールドに焦点を当てるべきです。私はこれまですべてのソリューションを試してみましたが、何も動いていないようにみえ。
edtPassword.requestFocus();
edtPassword.setFocusableInTouchMode(true);
edtPassword.getParent().requestChildFocus(edtPassword,edtPassword);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
フラグメントクラス:
public class ReloginpopupFragment extends DialogFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, R.style.DialogTheme);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.popup_relogin, container);
unbinder = ButterKnife.bind(this, view);
return view;
}
@Override
public void onResume() {
super.onResume();
KeyboardHelper.showSoftKeyboard(getContext(), edtUserName);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (sharedPreferenceManager.getCurrentUser().getUserID() != null) {
edtUserName.setText(sharedPreferenceManager.getCurrentUser().getUserID());
edtPassword.requestFocus();
}
setListener();
PackageManager packageManager = getContext().getApplicationContext().getPackageManager();
String packageName = getContext().getApplicationContext().getPackageName();
try {
String myVersionName = packageManager.getPackageInfo(packageName, 0).versionName; txtAppVersion.setText("App Version "+myVersionName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
}
ハムザ・カーン:
あなたは、これらの方法でのEditTextフィールドに焦点を当てることができます
プログラムによる:
edittext.requestFocus();
XMLを通じて:
<EditText...>
<requestFocus />
enter code here
</EditText>
しかし、主な問題は、onResumeメソッドをオーバーライドしている、あなたの活動のライフサイクルであります
@Override
public void onResume() {
super.onResume();
KeyboardHelper.showSoftKeyboard(getContext(), edtUserName);
}
あなたはonResume(へ)onViewCreated(からあなたのロジックを置き換えることができます)
@Override
public void onResume () {
super.onResume();
if (sharedPreferenceManager.getCurrentUser().getUserID() != null) {
edtUserName.setText(sharedPreferenceManager.getCurrentUser().getUserID());
edtPassword.requestFocus();
KeyboardHelper.showSoftKeyboard(getContext(), edtPassword);
} else {
KeyboardHelper.showSoftKeyboard(getContext(), edtUserName);
}
}