The activity_list.xml file code is as follows:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android: android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </LinearLayout>
The file code is as follows:
package .sample_6_4; import ; import ; import ; import .; import .; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class ListActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_list); ListView lv = (ListView)findViewById(); //Make an adapter to use ListView (new MyAdapter()); } class MyAdapter extends BaseAdapter{ @Override //Return the number of entries, the list of entries, such as how many entries are displayed on a screen public int getCount(){ return 20; } @Override //Determine the layout and content of each entry. The position represents the position of the entry, starting from 0 public View getView(int position, View converView, ViewGroup parent){ TextView tv = new TextView(); ("entry" + position); (23); (); return tv; } @Override public Object getItem(int position){ return null; } @Override public long getItemId(int position){ return 0; } } }
The above example of the Android ListView automatically generating list entries is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.