In Android, there are times when you need to load controls in an XML layout that is not in the original activity to enrich the interface of the Android program.
I am in the use of Viewflipper problems encountered.
public void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
Inflater= (Layoutinflater) Getsystemservice (layout_inflater_service);
View view=inflater.inflate (R.layout.myview, null);
ImageView view= (ImageView) Findviewbyid (R.id.imageview);
As we all know, we call Findviewbyid to get the control elements in the layout, but I found a java.lang.NullPointerException error while I was running. At first I thought the view was still empty, but it was found that the ImageView was empty. The IDs for MyView and ImageView have been successfully generated in R.java. After some time searching queries, we find that when we rewrite the adapter GetView () function, we get a control element that is passed through the
Such a form to obtain.
So it occurred to me that if the Findviewbyid method was invoked directly in the activity, its full form would be This.findviewbyid (). And the control I need is not in the layout of the activity itself, so when I get it, I change it to
That is, you can get the correct control by invoking the Findviewbyid method from the view where the control is located.
This is not a big problem in itself, but it will take some time if you don't pay attention to it, but I'm just taking notes for myself and making it easier for the vast majority of Android friends to develop.
The above is a small set to introduce the Android Findviewbyid get control back to the empty problem solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!