我正在尝试使用包含Autocompletetextview的片段构建android应用程序,我希望在显示片段时显示键盘。我已经尝试了一些方法,但是没有成功。
这是我的代码
XML文件
<AutoCompleteTextView
android:id="@+id/editArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:singleLine="true"
android:textColor="@android:color/primary_text_light"
android:gravity="right" >
</AutoCompleteTextView>
Run Code Online (Sandbox Code Playgroud)
我的Java片段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mLayout = inflater.inflate(R.layout.change_area, null, false);
area = (AutoCompleteTextView) mLayout.findViewById(R.id.editArea);
showHideKeyboard(true);
citiesList = singleToneCitiesList.getInstance().getList();
mAdapter = new CitiesAdapter(getActivity(),
R.layout.autocommplete_text, citiesList);
area.setAdapter(mAdapter);
area.setThreshold(1);
area.setOnItemClickListener(this);
return mLayout;
}
private void showHideKeyboard(boolean showHide) {
if (showHide) {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
area.requestLayout();
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInputFromWindow(getActivity()
.getCurrentFocus().getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
}
} else {
InputMethodManager imm = …Run Code Online (Sandbox Code Playgroud)