You may want to make that a last resort, creating a pure code class (ie, non-xml), since the layout-inflation process assigns the attributes specified to the classes properties. This assingment is NOT a trivial matter, and sometimes is a royal pain (especially if your reading attributes defined in other resources such as style sheets and such).
Rule of thumb - use layouts whenever possible. Even when you subclass and create your "own" custom view, use a layout and let android assign all the attributes to the view (during inflation), then you just got to handle any extra, view specific attributes that you may have defined for your view, which is usually only a few. On Tue, Jul 23, 2013 at 4:39 PM, Kai Xin <[email protected]> wrote: > The layer list is used as background of some controls. So FindViewById > could not find it. > > Like you said, to make it work first, I will try some work around e.g. > create the whole layer-list in the code rather than using the layerlist xml > file > > Thanks a lot for help. > > > On Tue, Jul 23, 2013 at 3:36 PM, Samus Arin <[email protected]> wrote: > >> Maybe you can try grabbing a reference to the layer list by "extracting" >> it from the view that host's it (ala .FindViewById type method). >> >> >> On Tue, Jul 23, 2013 at 10:29 AM, Samus Arin <[email protected]> wrote: >> >>> Man, I've ran into so many mysteries such as that... I don't want to >>> talk smack, b/c I highly respect the MonoDroid/Xamarin team for what they >>> did, but I'm fairly certain the Mono "layer" introduces many undocumented >>> bugs such as this. I've spent a 1/4 of my dev time this past year tracking >>> stuff like this down. There is probably some little magic trick that is >>> required. >>> >>> My advice to you is to find a workaround that can get you going, even if >>> its a convoluted, stinky code implementation. TRUST ME, JUST DO IT. And >>> then when you get time, make a toy app and try to get it working in there. >>> >>> I'll whip one up later, but I really got get cracking... Good luck for >>> now (try rebooting, I'm serious dude, both the device and your >>> workstation). Clean before and after reboot. >>> >>> >>> On Tue, Jul 23, 2013 at 10:14 AM, Kai Xin <[email protected]> wrote: >>> >>>> I tried for the hell of it but did not have any luck... >>>> And if I use the GetDrawable() to get an image, it is working. If I use >>>> it to get the layler-list, it dose not work. >>>> >>>> >>>> On Tue, Jul 23, 2013 at 3:10 PM, Samus Arin <[email protected]>wrote: >>>> >>>>> Just for the hell of it, try making all 4 of the density folders: >>>>> Drawable-xhdpi, Drawable-hdpi, Drawable-mdpi, Drawable-ldpi, >>>>> >>>>> >>>>> On Tue, Jul 23, 2013 at 10:06 AM, Samus Arin <[email protected]>wrote: >>>>> >>>>>> >>>>>> http://stackoverflow.com/questions/8859888/strange-exception-about-resource-not-found >>>>>> >>>>>> >>>>>> On Tue, Jul 23, 2013 at 10:03 AM, Samus Arin <[email protected]>wrote: >>>>>> >>>>>>> >>>>>>> http://stackoverflow.com/questions/10852711/getdrawable-returning-null >>>>>>> >>>>>>> >>>>>>> On Tue, Jul 23, 2013 at 10:01 AM, Samus Arin <[email protected]>wrote: >>>>>>> >>>>>>>> I just scanned my entire solution (its an enterprise class tablet >>>>>>>> app), and I'm not using Resource.GetDrawable() (it's commented out a >>>>>>>> few >>>>>>>> times, so I may have had trouble with it too)... >>>>>>>> >>>>>>>> Are you looking to manipulate the layout or something, like maybe >>>>>>>> change some of its properties based on run-time values/inputs ? >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jul 23, 2013 at 9:54 AM, Samus Arin <[email protected]>wrote: >>>>>>>> >>>>>>>>> Sorry, scratch that, I was confusing SetBackgroundResources() vs >>>>>>>>> SetBackgroundDrawable() >>>>>>>>> >>>>>>>>> >>>>>>>>> On Tue, Jul 23, 2013 at 9:50 AM, Samus Arin >>>>>>>>> <[email protected]>wrote: >>>>>>>>> >>>>>>>>>> Oh, try using GetResource(...) instead of GetDrawable(...) >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Tue, Jul 23, 2013 at 9:47 AM, Samus Arin >>>>>>>>>> <[email protected]>wrote: >>>>>>>>>> >>>>>>>>>>> Are u sure your not confusing the drawable layout file name with >>>>>>>>>>> the id-string of the root view inside the layout file (just a >>>>>>>>>>> precautionary >>>>>>>>>>> question) >>>>>>>>>>> On Jul 23, 2013 9:44 AM, "Kai Xin" <[email protected]> wrote: >>>>>>>>>>> >>>>>>>>>>>> I cleaned and rebuilt it but still got the error. >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> On Tue, Jul 23, 2013 at 2:06 PM, Samus Arin < >>>>>>>>>>>> [email protected]> wrote: >>>>>>>>>>>> >>>>>>>>>>>>> Try cleaning your proj/solution >>>>>>>>>>>>> On Jul 23, 2013 8:58 AM, "Kai Xin" <[email protected]> >>>>>>>>>>>>> wrote: >>>>>>>>>>>>> >>>>>>>>>>>>>> Hi, >>>>>>>>>>>>>> >>>>>>>>>>>>>> I have an xml file named "my_layerlist.xml" in the drawable >>>>>>>>>>>>>> and drawable-hdpi folder, which contains a layler-list. Then I >>>>>>>>>>>>>> want to get >>>>>>>>>>>>>> the instance of the layler list by: >>>>>>>>>>>>>> >>>>>>>>>>>>>> LayerDrawable layerDrawable = >>>>>>>>>>>>>> (LayerDrawable)Resources.GetDrawable(Resource.Drawable.my_layerlist); >>>>>>>>>>>>>> >>>>>>>>>>>>>> I got this error: >>>>>>>>>>>>>> Android.Content.Res.Resources+NotFoundException: File >>>>>>>>>>>>>> res/drawable-hdpi/my_layerlist.xml from drawable resource ID >>>>>>>>>>>>>> #0x7f02001e >>>>>>>>>>>>>> >>>>>>>>>>>>>> The resource exists in the Resource.Designer.cs: >>>>>>>>>>>>>> public partial class Drawable >>>>>>>>>>>>>> { >>>>>>>>>>>>>> // aapt resource value: 0x7f02001e >>>>>>>>>>>>>> public const int my_layerlist = 2130837534; >>>>>>>>>>>>>> ... ... >>>>>>>>>>>>>> } >>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>>> Does anyone know what the problem is? >>>>>>>>>>>>>> >>>>>>>>>>>>>> Thanks a lot >>>>>>>>>>>>>> >>>>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>>>> Monodroid mailing list >>>>>>>>>>>>>> [email protected] >>>>>>>>>>>>>> >>>>>>>>>>>>>> UNSUBSCRIBE INFORMATION: >>>>>>>>>>>>>> http://lists.ximian.com/mailman/listinfo/monodroid >>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>>> Monodroid mailing list >>>>>>>>>>>>> [email protected] >>>>>>>>>>>>> >>>>>>>>>>>>> UNSUBSCRIBE INFORMATION: >>>>>>>>>>>>> http://lists.ximian.com/mailman/listinfo/monodroid >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>> Monodroid mailing list >>>>>>>>>>>> [email protected] >>>>>>>>>>>> >>>>>>>>>>>> UNSUBSCRIBE INFORMATION: >>>>>>>>>>>> http://lists.ximian.com/mailman/listinfo/monodroid >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Monodroid mailing list >>>>> [email protected] >>>>> >>>>> UNSUBSCRIBE INFORMATION: >>>>> http://lists.ximian.com/mailman/listinfo/monodroid >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> Monodroid mailing list >>>> [email protected] >>>> >>>> UNSUBSCRIBE INFORMATION: >>>> http://lists.ximian.com/mailman/listinfo/monodroid >>>> >>>> >>> >> >> _______________________________________________ >> Monodroid mailing list >> [email protected] >> >> UNSUBSCRIBE INFORMATION: >> http://lists.ximian.com/mailman/listinfo/monodroid >> >> > > _______________________________________________ > Monodroid mailing list > [email protected] > > UNSUBSCRIBE INFORMATION: > http://lists.ximian.com/mailman/listinfo/monodroid > >
_______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
