首页 > 解决方案 > 使用变量字符串的 Textview 声明

问题描述

是否可以声明许多不同的 TextView。像 tv_concept1、tv_concept2、tv_concept3……等等。使用可变字符串?如果字符串为“1”,它将声明 tv_concept1。所以它会将 tv_concept1 文本更改为 Hi。但如果变量是 2,那么其他 TextView 会这样做。

    String textview = "tv_concept" + value;
    TextView textview = findViewById(R.id.textview);
    textview.setText("Hi");```

标签: android

解决方案


您可以使用对象数组。


推荐阅读