我有一个tabhost,每个标签我有一个活动组.
当应用程序启动时,我按下editText,键盘就会出现.
当我开始儿童活动,然后回到主要活动时,键盘不再出现.
我的启动子活动的代码
Intent i = new Intent(this, ShowAddFoodToSelection.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View view = ActivityGroupMeal.group.getLocalActivityManager().startActivity(DataParser.activityIDMeal, i).getDecorView();
ActivityGroupMeal.group.setContentView(view);
我的代码回到主要活动
ActivityGroupMeal.group.back();
而活动组中的后台代码:
public void back() {
try {
// if we set history.size() > 0 and we press back key on home
// activity
// and then on another activity we wont get back!
if (history.size() > 1) {
history.remove(history.size() - 1);
// call the super.setContent view! so set the real view
super.setContentView(history.get(history.size() - 1));
} else {
}
} catch (Exception e) {
if (history.size() >= 0)
super.setContentView(history.get(0));
}
}
我使用下面的代码在editText上设置了一个onClickListener:
private void keyboardShow() {
InputMethodManager inputManager = (InputMethodManager) ActivityGroupMeal.group.getSystemService(Context.INPUT_METHOD_SERVICE);
boolean test = inputManager.showSoftInput(editTextSearch, InputMethodManager.SHOW_IMPLICIT);
Toast.makeText(this, "show keyboard " + test, Toast.LENGTH_SHORT).show();
}
第一次返回true并且我从childactivity返回的时间返回false.
当我单击其他选项卡然后返回第一个选项卡,然后我单击editText它再次返回true.
编辑:我有一个临时修复,我在editTextbox上设置了一个onClicklistener然后我在那里显示键盘的代码
InputMethodManager inputManager = (InputMethodManager) ActivityGroupMeal.group
.getSystemService(Context.INPUT_METHOD_SERVICE);
// show keyboard , when it fails first switch tab and then try again
if (!inputManager.showSoftInput(null, InputMethodManager.SHOW_FORCED)) {
// switch from tab and back
// the keyboard wont show if we dont do this
ShowHomeTab parentActivity;
parentActivity = (ShowHomeTab) this.getParent().getParent();
parentActivity.goToTab(DataParser.activityIDTracking);
parentActivity.goToTab(DataParser.activityIDShowFoodList);
inputManager.showSoftInput(null, InputMethodManager.SHOW_FORCED);
}
当我从childactivity回来时,我首先必须在键盘显示之前用代码切换标签= /
有人得到了解释吗?
解决方法:
在我使用Activity Group的应用程序中,我使用下面的代码来解决同样的问题
YOUR_EDIT_TEXT.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(searchName
.getApplicationWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
它工作正常.所以试试这段代码.