是否可以通过 id 在查找视图中将对象参数作为 id 传递
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(Integer.parseInt("You Answer Can't be Greater Than"+(greater_num));
} else {
}
}
你可以这样做:
TextView textView = findViewById(getResources().getIdentifier(Text_ID, "id", getPackageName()););
其中 Text_ID 是您的视图 ID(不带 R.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(Integer.parseInt("You Answer Can't be Greater Than"+(greater_num));
} else {
}
}
你可以这样做:
TextView textView = findViewById(getResources().getIdentifier(Text_ID, "id", getPackageName()););
其中 Text_ID 是您的视图 ID(不带 R.id.
前缀)