本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

editText.setText(string) 不起作用,但 textView.setText(string) 总是有效,奇怪的区别

发布于2022-04-18 03:15     阅读(544)     评论(0)     点赞(29)     收藏(2)


所以我希望 editText.setText (str) 与 textView.setText (str) 一样工作

我正在将一个字符串从 WebView 发送到 Android @JavascriptInterface。奇怪的是,只要屏幕键盘弹出/激活,EditText 只会在 WebView 中单击发送按钮时生成 setText(字符串)。

如果您在键盘下方看不到输入字段,则:

  1. 我关闭屏幕键盘,
  2. 单击 WebView 中的发送按钮,
  3. 再次单击任何输入字段(或在 android Input 中),以便弹出屏幕键盘,
  4. 此时字符串显示在@JavascriptInterface 的EditText 中,从WebView 接收。

有趣的是,如果我在 TextView 中显示/接收字符串,它可以在没有任何现场键盘状态的情况下工作,或者单击单击。

我该怎么办,我已经尝试过了

一个可运行的调度程序,在 500 毫秒后将字符串发送到 EditText,

并尝试调用外部函数,并在 EditText 之前显示带有 toast 的消息字符串 - 所以消息总是到达 - 只有当键盘仍然在 WebView 中弹出时,只有 EditText 才会显示。

尝试向 WebView 发送单击事件,但在此焦点中键盘不会弹出

    @JavascriptInterface
    public void showMessageInEditText(String str) {

         int test = 1;
         // EditText   not happy
         if(1==test){  EditText editText = (EditText) findViewById(R.id.edit_txt_id);
            editText.setText(str);  }

         if(2==test){  TextView editText = (TextView) findViewById(R.id.edit_txt_id);
             editText.setText(str);  }
         
         // TextView   always works:
         if(3==test){  TextView textView = (TextView) findViewById(R.id.txt_id2);
             textView.setText(str);  }
    }
    /*
    a strange difference:
    
    textView.setText(str);  // test=3          always works
    
    editText.setText(str);  // test=1 test=2   only works if 
        the onscreen keyboard is popped up / active, 
        for input in the WebView active, 
        and the send button is clicked exactly during this time, 
        the onscreen keyboard is popped up
    
    */

WebViev 到 Android java

我更新了程序,尝试发送到另一个Activity2然后就可以了

发送到第二个活动是好的


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/417420/e403d21fda7ba8c5b13d/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

29 0
收藏该文
已收藏

评论内容:(最多支持255个字符)