FindViewById(int) returns null for custom views, but not Android built-ins?

It's very difficult to find problem without actual sources. I've created sample project based on your posts and its fully works. I believe that there is very simple mistake and you'll find it.

If you want, you may try it.

The problem is that, yes, it works, and I can get references to UI elements such as Button and CheckBox. But my custom widgets get returned to me as null despite showing up in the layout and being fully interactive. This seems to be because their IDs are being set incorrectly in View's constructor, but I have no idea how that could possibly happen.

– Brigham Toskin Oct 20 at 16:32.

Yeah... I'm an idiot. View was of course setting the correct ID, and then one of my init methods went back and clobbered it. Facepalm.

This seems more like a question comment. Its your call whether or not to acknowledge @ it is much appreciated that you closed the question. But you are NOT an idiot!

It would be better to write out a clearer explanation here (you overwrote the correct ID set by view? ) and leave out the self-deprecation and words like clobbered. No harm done, but don't put yourself down like that!

– Feral Oink Oct 21 at 2:04.

The Situation: I have some custom components in my layout. I have a common layout frame that I load in my Activity base class's onCreate(), and then load my content layouts in my implementations using an inflater, setting the root to the content column of the main layout. The Problem: When I grab a reference to the Views, to actually extract the user's input, Activity.findViewById() returns null.

It is perhaps a clue that the CheckBox and Button I have in the layout do NOT return null; I get a valid reference to the widget. Things I've Tried: I know I am properly loading and inflating the layout xml, because everything shows up, and the standard Views in the same layout can be found by ID. I can interact with my Views and put content into them and everything, but I can't get a reference to them in my code.

I have tried cleaning the project, multiple times. R.id is fresh and up-to-date.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions