One, a simple list of TextView
Public classFirstactivityextendsActivity {Privatestring[] data = {"Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango","Apple", "Banana", "Orange", "Watermelon","Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango"}; @Overrideprotected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (r.layout.first_layout); arrayadapter<string> adapter =NewArrayadapter<string> (//arrayadapter Array AdapterFirstactivity. ThisAndroid. R.layout.simple_list_item_1, data);The first parameter, the context object, the second argument, an official built-in layout ID (this is a texview); The third argument, the incoming dataListView ListView = (ListView) Findviewbyid (R.id.listview); Listview.setadapter (adapter); }}
Second, how can be fun things only text view (to point Complex) 1. Create a new class for storing fruit
Public class Fruit { private String name; Private int imageId; //constructor initialization Public int imageId) {This . Name = name; this. imageId = ImageId; } Public String GetName () { return name; } Public int Getimageid () { return imageId; }}
2. Create a custom layout file
Used to describe the layout, waiting to be called
<LinearLayout xmlns:Android="Http://schemas.android.com/apk/res/android" Android:Layout_width="Match_parent" Android:Layout_height="Match_parent" Android:Orientation="Horizontal"> <ImageView Android:ID="@+id/fruit_image" Android:Layout_width="50DP" Android:Layout_height="50DP" /> <TextView Android:ID="@+id/fruit_name" Android:Layout_width="Wrap_content" Android:Layout_height="Wrap_content" /></LinearLayout>
3. Custom adapter, inherited from Arrayadapter
ListView of UI Controls