Reputation: 21
In part of my android application I am trying to show the text I am typing as it is being typed WITHOUT a button/button listener. In other words I want to see the text in an EditText sent in real time to a TextView. Is this possible?
Upvotes: 1
Views: 1805
Reputation: 147
//To open keyboard forcefully, mention the code into any listener or oncreate
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
//To Trace Pressed Key
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_A:
{
textview.setText("A");
//your Action code
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 2
Reputation: 437
You can use an EditText TextChangedListener.
textView = (TextView)findViewById(R.id.text_view);
editText = (EditText)findViewById(R.id.edit_text);
editText.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
textView.setText(editText.getText().toString());
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
Upvotes: 0
Reputation: 1257
You can accomplish this by calling addTextChangedListener on the EditText, and creating a new TextWatcher.
EditText editText = findViewById(R.id.edit_text);
editText..addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
changeTextView();
}
@Override
public void afterTextChanged(Editable s) {
}
});
Upvotes: 0