1, in the layoutinflater usually have the following 2 kinds of initialization method, in active call is very easy.
1, Layoutinflater inflater=layoutinflater.from (context); 2, Layoutinflater inflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service);
2, create Myadapter class time in the GetView () method when using Layoutinflater, usually will mainactivity in, will the context context into, This can be initialized in the GetView () method using the method above. For GetView () parameters, check the API documentation is very abstract, by setting a breakpoint in the code in memory to see the parameters found, theparent is the ListView. Convertview is a listview
Cache (data obtained).
public view getView (int position, View Convertview, ViewGroup parent) {//TODO auto-generated method Stub Layoutinflater inflater=layoutinflater.from (context);//mainactivity.inflater;// Layoutinflater Inflater = (layoutinflater) context.getsystemservice//(Context.layout_inflater_service); View view=inflater.inflate (r.layout.item2, NULL);
//here is the item2.xml passed into the View object, so you can use method, Setcontentview (R.layout.activity_main)
in the main function is also the load XML, which displays the contents of the//xml in the current activity. Because the activity of the main function inherits the view, it is actually a container of the view,
so the main function can use the Findviewbyid method directly, can only find the ID of the space in the Activity_main, so if you want to use in other classes Span style= "color: #ff0000;" The
control in >activity_main can be mainactivity Act is passed in as a member of a class, and then Act.findviewbyid ( );
TextView text= (TextView) View.findviewbyid (r.id.tv_name); Text.settext (Personlist.get (position). GetName ()); TextView text2= (TextView) View.findviewbyid (R.id.tv_money); Text2.settext (Personlist.get (position). Getmoney () + "") ;
TextView text0=new TextView (context);
Text0.settext ("Hello");
return view;
The return value here, if used after a View.findviewbyid control, if multiple controls are either returned to view or returned with controls unrelated to these controls such as Text0,
You cannot return one of these, or an exception will occur, but if you only Findviewbyid a control, you can return the control. }
The use of Android learning Layoutinflater to compress multiple TextView components into a single view control in Myadapter GetView () and display them in a ListView