开发者

Android catch keys [closed]

开发者 https://www.devze.com 2023-01-20 13:03 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_运维技巧
Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_运维技巧

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 7 years ago.

Improve this question

I'm new to android programming, and I was wondering if there was an event or something for any virtual keyboard input. I was also wondering if there is an event for when you try to send a text message, or maybe a way to send a text message. I want to use 2.2. thanks.

After doing some reading it looks like this isn't possible. What I wanted to do was globally catch keys from the virtual keyboard.


If you have an EditText and want to catch characters typed into it from the virtual keyboard you can use a TextWatcher. Below is an example how to update a character counter:

edittext.addTextChangedListener(new TextWatcher() {
  @Override
  public void onTextChanged(CharSequence s, int start, int before, int count) { }
  @Override
  public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
  @Override
  public void afterTextChanged(Editable s) {  
    /* get text length and update the counter */
    counter.update(s.length());
  }
});


You can use either a TextWatcher or a KeyListener to react on button events. Whereas the TextWatcher doesn't react on key events it rather reacts whenever the text of an EditText control changes. So it depends on you needs which way you go.

Regarding your question about the text messages I think this question will should help you understanding how to send an text message.


it's not possible

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号