I want to create 1 edit text with the below condition:
– User can not focus on this control in normal.
– When user click on this control, soft-keyborad is displayed and user can input into this control
– When user press enter on this soft-keyborad or back on device, it is closed and back to normal view with control is not focus.
I tried the below code but not work 🙁
When starting, control is not focus: ok
When click on control, at the first click, control is focus but not display soft-keyborad
In the second click, display soft-keyborad
- When press enter button in soft-keyborad: back to screen with control is not focus: OK
-
When press back button device, back to screen with control is still focus : not ok
public void onCreate(Bundle savedInstanceState) { final EditText txtSearch = (EditText)this.findViewById(R.id.p60004_txt_search_str); txtSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub txtSearch.setFocusable(true);//(false); txtSearch.setFocusableInTouchMode(true); txtSearch.requestFocus(); } }); txtSearch.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { String strSearch = txtSearch.getText().toString(); if (strSearch != null && strSearch != ""){ searchFriend(UserAPIConstants.FRIEND_SEARCH_TYPE_SC, strSearch); } hideSoftKeyboard(v); txtSearch.setFocusable(false); txtSearch.setFocusableInTouchMode(false); } return false; } }); public void hideSoftKeyboard (View view) { InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }
In your xml which has edittext put these values for the layout node
and dont put any focusable or focusable in touch mode attributes for your edittext..
Then in your code in onKey method remove thse lines..
and put
And You should override this method
like this..