Just learned listview, refer to online tutorials
Http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html
Implemented a listview by myself, using SimpleAdapter, slightly changed
The Code is as follows:
Public class SListViewActivity extends Activity {
/** Called when the activity is first created .*/
Private ListView iLv;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
ILv = (ListView) this. findViewById (R. id. lv );
SimpleAdapter ada = new SimpleAdapter (this, getData (), R. layout. vlist, new String [] {"title", "info", "img "},
New int [] {R. id. title, R.id.info, R. id. img });
ILv. setAdapter (ada );
}
Private List <Map <String, Object> getData ()
{
List <Map <String, Object> list = new ArrayList <Map <String, Object> ();
Map <String, Object> map = new HashMap <String, Object> ();
Map. put ("title", "G1 ");
Map. put ("info", "google ");
Map. put ("img", R. drawable. i1 );
List. add (map );
Map = new HashMap <String, Object> ();
Map. put ("title", "G2 ");
Map. put ("info", "google 2 ");
Map. put ("img", R. drawable. i1 );
List. add (map );
Return list;
}
------
Xml Code
Main. xml
<? 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"
Android: orientation = "vertical">
<ListView
Android: id = "@ + id/lv"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
/>
</LinearLayout>
Vlist. xml: The layout file of the custom listview.
<? 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">
<ImageView
Android: id = "@ + id/img"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_margin = "3px"
/>
<LinearLayout
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: orientation = "vertical"
>
<TextView
Android: id = "@ + id/title"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textColor = "# ffffff"
Android: textSize = "22px"
/>
<TextView
Android: id = "@ + id/info"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textColor = "# ffffff"
Android: textSize = "12px"
/>
</LinearLayout>
</LinearLayout>
After it was just made, there was no way to run it. In the end, it was found that TextView was written incorrectly here. After correct modification, it can be run.