The project needs to keep the title bar, by clicking the button on the left side of the title bar, pop-up drop-down menu, switch to the right side of the interface, so think of using fragment this class, you can switch activity very well, but there are a lot of problems when using:
1
. Public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) { View VI = Inflater.inflate (R.layout.activity_price, container,false);}
<span style= "color: #ff0000; Background-color:rgb (255, 255, 102);" > The above code is wrong, when creating fragment, such initialization code I forgot to write return value, causing the program error, so go to don't forget to add a return vi;</span>
2. When using Findviewbyid, get an ID, get in fragment and activity a bit different, slightly unnoticed, it is possible to obtain a null value NULL:
The following are the wrong uses:
A.<pre style= "Background-color:rgb (255, 255, 255); Font-family:consolas; font-size:13.5pt; " ><span style= "Color:rgb (102, 14, 122); "><strong></strong></span><pre style=" Background-color:rgb (255, 255, 255); Font-family:consolas; font-size:13.5pt; " >allonehorizontalscrollview
Tableheaderview = (Allonehorizontalscrollview)
GetView. Findviewbyid (R.id.
horizontalscrollview_1);
B.Allonehorizontalscrollview
getactivity. Findviewbyid (r.id. Horizontalscrollview_1);
Such code gets the value tested to be empty, the correct way is to use the above generated VI:
<span style= "Font-family:consolas;" ><span style= "FONT-SIZE:18PX;" ><strong><span style= "color: #660e7a;" > </span></strong></span></span><pre name= "code" class= "Java" ><span style = "COLOR: #660e7a;" > View VI = inflater.inflate (R.layout.activity_price, container,false); Load Font loadfonts (); Tableheaderview = (allonehorizontalscrollview) </span><span style= "color: #ff0000; Background-color:rgb (255 , 255, 102); " >vi.</span><span style= "color: #660e7a;" >findviewbyid (r.id.horizontalscrollview_1); Tabledataview = (allonehorizontalscrollview) </span><span style= "color: #ff0000; Background-color:rgb (255, 255, 102); " >vi.</span><span style= "color: #660e7a;" >findviewbyid (r.id.horizontalscrollview_2); Tableheaderview.setscrollview (Tabledataview);</span>
Hope to have a little help to the students who use fragment.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Fragment Get Id,findviewbyid empty