OnClick到TextView Android [英] OnClick to TextView Android

查看:109
本文介绍了OnClick到TextView Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单击按钮在文本视图"中设置文本,这两个按钮都存在于同一活动中?

How to set text in the Text View by using button on click both are present in the same Activity?

在使用相同的文本视图"时,我已经使用了文本视图".

I have already used the Text View on using the same Text View the Stopped working

推荐答案

以下代码可为您提供帮助.

Here is the code that can help you with this.

Button button;
TextView textView;

button = (Button) findViewById(R.id.main_button);
textView = (TextView) findViewById(R.id.main_text);
// set the text view inside the button's OnClickListener() method

button.setOnClickListener(new View.OnClickListener(){
   @Override
   public void onClick(View v){
      textView.setText("Hello World");
   }
});

这篇关于OnClick到TextView Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆