英文:
Is it possible to pass an object parameter as an id in the find view by id
问题
这是我自然而然地完成这个任务的方式,还有其他可能的可行方法吗?
public void error_checker(String Text_ID, int id, int id_2, String greater_num) {
if (id > id_2) {
TextView TextView = findViewById(R.id.Text_ID);
TextView.setText("你的答案不能大于" + (greater_num));
} else {
}
}
英文:
Here is how I would naturally do this, are there any other possible ways that work?
public void error_checker(String Text_ID, int id,int id_2,String greater_num){
if (id>id_2){
TextView TextView = findViewById(R.id.Text_ID);
TextView.setText(Integer.parseInt("You Answer Can't be Greater Than"+(greater_num));
} else {
}
}
答案1
得分: 0
你可以像这样做:
TextView textView = findViewById(getResources().getIdentifier(Text_ID, "id", getPackageName()));
其中,Text_ID 是你的视图的ID(不带R.id.
前缀)。
英文:
You can do it like this:
TextView textView = findViewById(getResources().getIdentifier(Text_ID, "id", getPackageName()););
Where Text_ID is the ID of your view (without the R.id.
prefix)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论