Reputation: 551
I have this annoying problem. My app has 2 activities (tabs) Activity1:listview, Activity2:editText+listview. App starts with Tab1(Activity1). When i open 2nd Activity (with edittext), no matter if EditText is selected or not (programmable), when i click on EditText, nothing happens (softKeyboard should appear). Only solution is to change activity (click on Tab1 widget) and return to activity 2 - after this tab swap, keyboard works fine.
Part of XML layout with edittext:
<EditText
android:hint="Wyszukaj..."
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="45dp"
android:inputType="textAutoComplete|text"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
>
and here is 2 overrided method from Activity2
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
this.db = DataBase.getInstance();
this.ds = DataSource.getInstance();
this.prepareListView();
}
@Override
protected void onResume() {
super.onResume();
this.doubleBackToExitPressedOnce = false;
}
private void prepareListView() {
sbal = this.db.getAllStops();
adapter = new StopListAdapter(this, sbal);
lv = (ListView) findViewById(R.id.tab2list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(onClick);
EditText et = (EditText) findViewById(R.id.editText1);
et.addTextChangedListener(changeWatcher);
registerForContextMenu(lv);
}
Do you have any ideas, how XMLcode and activity code should look like in this case?
Upvotes: 3
Views: 18145
Reputation: 31
The workaround for this, to explicitly call the soft keyboard on onCreate() and onResume() method.
editText.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if (editText.isEnabled() && editText.isFocusable()) {
editText.post(new Runnable() {
@Override
public void run() {
Context context = getApplicationContext();
final InputMethodManager imm =
(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editor,InputMethodManager.SHOW_IMPLICIT);
}
});
}
}
});
Hope this helps :)
Upvotes: 0
Reputation: 51
See this answer. It solved the same problem for me:
Keyboard not shown when i click on edittextview in android?
and try this code
mEditText.clearFocus();
Upvotes: 5
Reputation: 627
try {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(
YourEditText.getWindowToken(), 0);
} catch (Exception e) {
e.printStackTrace();
}
Try this with edittext...
Upvotes: 0
Reputation: 727
try dropping out the two lines about "focusable" from xml. i have something very similar and it works without them
Upvotes: 0