XML Inflater not seeing any of the views?

放肆的年华 提交于 2019-12-01 13:34:48
Dan Breslau

As mreichelt pointed out in a comment, your use of Layout.inflate seems suspicious. You probably want to do something more like this:

    // Assume that the XML file from your question (above) is named MyLayoutFile.xml 
    // Digital is your derived layout class
    Digital layout = (Digital) inflater.inflate(R.layout.MyLayoutFile, this, true);

    mReadDisplay = (TextView) layout.findViewById(R.id.digi_reading);
    //...
    mHeadDisplay = (TextView) layout.findViewById(R.id.digi_header);
    //...
    mMeasureDisplay = (TextView) layout.findViewById(R.id.digi_measurement);

and so on. Notice especially that the ID passed into inflater.inflate is prefixed with R.layout., whereas the ID passed into findViewById is prefixed with R.id. (Unfortunately, passing the wrong kind of resource identifier will never generate a compile-time error.)

I think you need to define the first tag as <merge>-tag instead of defining your own class again. At least I did it this way a few days ago. Here is more information: http://developer.android.com/resources/articles/layout-tricks-merge.html

You are doing it wrong, you only call inflate for the root view.

com.android.appionresourcemanager.Widgets.Digital mDigital = (Digital)View.inflate(this, R.layout.mylayout, null);
 mReadDisplay = (TextView)mDigital.findViewById(R.id.digi_reading);
 //....

hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!