0

In my activity there is a button and a textview .What I am trying is when the user clicks on a button the keyboard shows up ,and whatever the user types there that text should be displayed in textview.I'm able to show keyboard on button click but can't get the text in textview. I tried textview.setFocusableInTouchMode (true); & textview.requestFocus (); on button click ,but still can't get the text.

As suggested, I added edittext instead of textview and also added text changed listener on it , but not able to achieve what I want .The keyboard should appear on button click and then show the text in edittext .

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Neha
  • 389
  • 4
  • 8
  • 24

2 Answers2

3

you can solve this in 2 ways

method 1:

add textChangeListener to your EditText, like this

yourEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            yourTextView.setText(charSequence);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

method 2:

use the only editText and set EditText background color same as your screen background color then your editText will look like a textView and automatically typed value will be there

like this :

android:background="your screen background color"

This might help you

0

You can use OnKeyListener for example,

@Override
public boolean dispatchKeyEvent(KeyEvent keyEvent) 
{
    int keyAction = keyEvent.getAction();
    if(keyAction == KeyEvent.ACTION_DOWN) //any action event you prefer
    {
       char pressedKey = (char) keyEvent.getUnicodeChar();
    }
    //append the char to the string variable
    //return 
}

You can set the string to TextView.

Chithra B
  • 586
  • 2
  • 9