Inflater與findViewById()區別


/* *
             * Inflater英文意思是膨脹,在Android中應該是擴展的意思吧。 LayoutInflater的作用類似於
             * findViewById(),不同點是LayoutInflater是用來找layout文件夾下的xml布局文件,並且實例化! 而
             * findViewById()是找具體某一個xml下的具體 widget控件(如:Button,TextView等)。
             
*/

             //  LayoutInflater的作用是,把一個View的對象與XML布局文件關聯並實例化
            LayoutInflater inflater = (LayoutInflater) listviewActivity. this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

             //  LayoutInflater的作用是,把一個View的對象與XML布局文件關聯並實例化
            View itemView = inflater.inflate(R.layout.listview_item,  null);

             //  View的對象實例化之后,可以通過findViewById()查找布局文件中的指定Id的組件
            TextView title = (TextView) itemView.findViewById(R.id.txttitle);
            TextView text = (TextView) itemView.findViewById(R.id.txtContent);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM