Freewind
Freewind

Reputation: 198218

How to implement: click a button, then user can input something to a EditText

There is an EditText(edit) and a Button(btn) on screen.

User can click the EditText to input something, and I also want when user click the button, user can input something to the EditText too.

I tried:

btn.setOnClickListener(new View.OnclickListener() {
   public void onClick(View v) {
       edit.requestFocus();
       edit.performClick();
   }
});

But it doesn't work. Although edit get the focus, but the IME doesn't show.

Upvotes: 0

Views: 172

Answers (1)

Archie.bpgc
Archie.bpgc

Reputation: 24012

performClick() works only when you implement the onClickListener for that particular View.

So, do this in the onClick of your EditText or Button

edit.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT);

Upvotes: 2

Related Questions