繁体   English   中英

如何从 Java 设置 TextView 的文本

[英]How to set the text of a TextView from Java

我需要随机化TextView的文本。

我知道如何通过以下示例随机化这些东西:

String[] epicstring={"a", "b", "c", "d", "e"};
Random r=new Random();
int randomnumber= r.nextInt(epicstring.length);
System.out.println(epicstring[randomnumber]);

我想将 output 文本转换成TextView ,但我该怎么做呢?

TextView textView = (TextView) findViewById(R.id.MyTextView); // use with ID of your TextView
textView.setText(epicstring[randomnumber]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM