inflate()和findViewById(),findviewbyid

來源:互聯網
上載者:User

inflate()和findViewById(),findviewbyid

1.findViewById()是View對象的方法,先通過inflate()方法得到View,調用這個View對象的getViewById()方法,就能得到這個View樹上的子View。

2.inflate()函數可以通過getSystemService()方法得到,參數是LAYOUT_INFLATER_SERVICE。

3.inflate()函數的第一個參數是布局檔案的R引用,第二個參數是根 ViewGroup,也就是從哪個ViewGroup節點開始渲染。對於第二個參數,需要執行個體化這個VIewGroup,可以這麼做,在XML布局檔案中設定這個root的id,然後用findViewById()方法通過id就能得到它,比如

  • View layout = inflater.inflate(R.layout.toast_layout,(ViewGroup) 
  • findViewById(R.id.toast_layout_root));


android findViewByid方法

不能獲得buttonB
 
各位大俠幫忙呀 為何Viewinflate報null 指標錯誤

額 解決了 用了一個適配器裡用過的方法 我無非是想得到一個progressbar的列表 用這方法可以得到,得到了就能做很多事了 嘿嘿 android new progressbar預設的樣式是圓形的 網上講的什麼反射機制去改變某個屬性來實現 我覺得對我這種初學者很麻煩 就用這個方法吧linear.addView(txt,params); View view =View.inflate(context,R.layout.bookprogressbar, null); if(view.findViewById(R.id.bookprogressbar) instanceof ProgressBar){ progressbar=(ProgressBar)view.findViewById(R.id.bookprogressbar); progressbar.setTag(xxxxx); progresslist.add(progressbar); progressbar.setProgress(Integer.parseInt(xxxxx); map.put("progressbar", progressbar); linear.addView(view,params); }
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.