I have a tabhost and for each tab i have a activitygroup.
When the app starts and i press on a editText the keyboard comes out. When i start a child activity and then go back to the main activity the keyboard doesnt come out anymore.
My code for starting the the subactivity
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);
my code to go back to the main activity
ActivityGroupMeal.group.back();
And the back code in the activitygroup:
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));
}
}
i set a onClickListener on the editText with the folowing code:
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();
}
The first time it returns true and the time i come back from a childactivity it returns false.
When i click on a other tab and then back on the first tab, and then i click on the editText it returns true again.
Edit: i got a temporary fix, i set a onClicklistener on the editTextbox and then there i show the keyboard with code
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);
}
When i come back from the childactivity i first have to switch tabs with code before the keyboard will show =/
anyone got a explanation for that ?
In my application where I used Activity Group, I used below code to resolve the same issue
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;
}
});
and it was working fine. So try out this code snippet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With