android - 将数据动态添加到更多 TextView
问题描述
是否可以将文本动态添加到 xalm 中定义的多个文本视图?例如,在一个循环中:
var textView1 = FindViewById<TextView>(Resource.Id.textView1);
var textView2 = FindViewById<TextView>(Resource.Id.textView2);
var textView3 = FindViewById<TextView>(Resource.Id.textView3);
var content = "Add me to more at one textView"
for (i = 1; i = 3; i++)
{
// add me;
}
我可以很容易地做到这一点,因为它通过在布局中调用 GetChildAt () 以编程方式添加 textview。如果 textView 在 xalm 中定义,是否可以添加动态?
解决方案
假设您的文本 ID 是 text1、text2、tex3 等。使用:
for (int i=1; i<numberOfTextsViews; i++) {
int id = this.getResources().getIdentifier("text" + i, "id", getPackageName());
TextView temp = findViewById(id);
temp.setText("text you want to add to all your texts");
}
推荐阅读
- firebase - 在firebase中重置密码时更改电子邮件接收器
- powershell - 按组名将大 CSV 拆分为多个文件小 csv 并保持输出格式
- android - Android上的POST错误
- json - SQL修改替换json字符串值
- javascript - 根据服务器的日期显示今天-明天
- javascript - 如何在 NodeJS 回调中获取 MongoDB 的 collection.aggregate() 的结果?
- c# - 如何确保在 MessageReciever 关闭期间完成 MessageHandler 委托?
- java - 根据输入和方法的数量列出所有组合
- vue.js - 使用自定义数据动态创建组件
- kvm - 无法打开虚拟机管理器