所以我有更多像这样的imageView:
imageView1
...
imageView8
int defendPosition = defend(); // This is random generated number from 1-8;
String imageID = "imageView" + defendPosition;
int resID = getResources().getIdentifier(imageID, "id", getPackageName());
Log.i("resID", " "+ resID); // it logs value is 0
secondMove = findViewById(resID);
secondMove.setTranslationY(-1500); // When I try to run this, it says null refference;
我需要获取正确的ID
答案 0 :(得分:0)
尝试
int resID=this.getResources().getIdentifier(imageID,"id",getActivity().getPackageName())