android Textview问题

weixin_36528687 2018-10-15 03:39:53
点击按钮,在Textview里会出现很多人名,当人名里出现 张三 的时候,在edittext里显示“出现” 求助要怎么写啊
...全文
151 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_36528687 2018-10-15
  • 打赏
  • 举报
回复
多谢
hs1002 2018-10-15
  • 打赏
  • 举报
回复
把 if(-1!= (textView.getText().toString().indexOf("423424234")))
{
editText.setText("出现");
}要放在点击监听里吧
weixin_36528687 2018-10-15
  • 打赏
  • 举报
回复
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );
        textView = findViewById( R.id.textview );
        editText = findViewById( R.id.edittext );
        button1 = findViewById( R.id.button );
        button1.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText("23123 423424234");
            }
        } );
        /*if (textView.getText().toString() == "23123 423424234") {
        editText.setText( "84646546" );
            }*/
        if(-1!= (textView.getText().toString().indexOf("423424234")))
        {
            editText.setText("出现");
        }

        }
我这样写的没达到效果,不过把textview的text直接设置成23123 423424234 就可以了 请问是哪里的问题啊
usecf 2018-10-15
  • 打赏
  • 举报
回复
Textview tv = null;
if(-1!= (tv.getText().toString.indexOf("张三")))
{
edittext.setText("出现"); //或者把字符串写到string.xml中 通过R.string.show 类似这种调用
}

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧