Originally today is thinking to review the previous knowledge (to do a simple thing to do before), and then cheerfully prepared to summarize the use of adapter, but encountered the first and simplest of a arrayadapter has been hit and beaten.
This one may be more suitable for a rookie like me. Old driver can skip over! (above his business can see, maybe it will be useful)
1, member variable in the direct ListView lv_array= (ListView) Findviewbyid (R.id.lv_array) See clearly is in the member variable , this error I tune for two hours, the process will not say ... Compare DT, later thought carefully, and looked carefully to see only suddenly, in the implementation of Setcontentview (R.layout.activity_main), how can find the view of it? Therefore, the order of the method call determines the Findviewbyid this method can not be used in advance! In other words, after Setcontentview (R.layout.activity_main)
ListView lv_array= (ListView) Findviewbyid (R.id.lv_array) or pre-defined Lv_array (declared at member variables) and then assigns a value lv_array= (listview) Findviewbyid (R.id.lv_array), as long as Findviewbyid () This method is not in front of the line.
2. Use arrayadapter<string> adp=new arrayadapter<> (this, r.layout.v_arrayadapter, str); A red tag refers to a file with the following code:
<?xml version= "1.0" encoding= "Utf-8"?><TextView xmlns:android= "http://schemas.android.com/ Apk/res/android " android:id=" @+id/tv_array " android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:textcolor= "#0f0" android:text = "Wushuju" />
Just a TextView component! Emphasize "only", my mistake is in this place, very silly X to write a textview in a linearlayout, the result program always crashes. (The original direct use of the simpleadapter, no requirement for this, so naturally wrong) error code is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android " android:layout_width=" Fill_parent " android:layout_height=" Fill_parent " ><TextView android:id= "@+id/tv_array" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:textcolor= "#0f0" Android:text= "Wushuju" /></linearlayout>
The lesson to me is, do not do, never know what the pit is waiting for you!
Talk about first here, continue to climb the pit!
Adapter, think of what to say (there will be an official version later)