getIdentifier
int id = context.getResources().getIdentifier("tv_col"+(i+1),"id",context.getPackageName()); textView = findViewById(id);
?除此之外,它還可以用于獲取一些其他res資源(如,string字串,圖片),對應第二引數可能要修改成 “string”
【想法來源】
在Android開發程序中我們都會使用 findViewById(R.id.控制元件id) 的形式獲取一個控制元件,而后面的 id 是在 xml 檔案中設定了相應的名稱,才能獲取到,而在 JavaScript 中Jquery 會使用 $("#控制元件id"),甚至在使用的程序中會使用一些拼接比如 $("#abc"+x)這種形式,所以有些時候我就想在Android中去使用這樣一種方式去獲取應用的控制元件,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/11352.html
標籤:Android
