Reputation: 24967
I want to change keyboard input ,
Example :
When user press a , it will be show c
I tried to use TextWatcher
and it hang because after calling setText
, it will be arrive again TextWatcher event. So, it will deadlock and not working.
setOnKeyListener
is not working also. onKey
event arrive when Enter. Not arriving when I press a or b.
It is possible to change text input key in EditText Android ?
Update: setOnKeyListener
final EditText edittext = (EditText) findViewById(R.id.editText1);
edittext.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int keycode, KeyEvent event) {
// TODO Auto-generated method stub
Log.i("onKey", "Arrive Keypress");
if (event.getAction()!=KeyEvent.ACTION_DOWN)
return true;
if (event != null&& (keycode == KeyEvent.KEYCODE_ENTER)) {
applySearch();
return true;
}
return false;
}
});
Upvotes: 2
Views: 1849
Reputation: 3506
Use TextWatcher
, but use it smart. When you call setText
create boolean flag == true
, and check every time this flag
in onTextChanged
. Hope its help.
public class MyActivity extends Activity implements TextWatcher {
EditText et;
boolean flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText) findViewById(R.id.et);
et.addTextChangedListener(this);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(flag)
{
flag = false;
return;
}
else
{
//do same staff
flag = true;
et.setText("new text");
}
}
@Override
public void afterTextChanged(Editable s) {
}
}
Upvotes: 3
Reputation: 1
Yes its feasible,I use sling keyboard(you could find this app on Google Play).You could choose it as default under keyboard setting in your phone.
Rgds,
Ambar
Upvotes: 0