嗨,我正在尝试从字符串中获取片段中某些视图的 id,但是它似乎不起作用......片段是否有特殊情况?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View singleplayerView = inflater.inflate(R.layout.singleplayer_tab, container, false);
setupMap();
return singleplayerView;
}
private void setupRank() {
TextView view = (TextView) getByStringId("rank0");
view.setText("hello");
}
private final View getByStringId(final String id) {
return findViewById(getResources().getIdentifier(id, "id", getActivi
ty().getPackageName()));
}
所以我试图在用于我的片段的布局中设置 textView 字段 rank0 ......但现在它得到一个 NUllPointer 因为它找不到 id
谢谢