Public class ListViewActivity extends ListActivity
{
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
// SetContentView (R. layout. main );
SimpleAdapter adapter = new SimpleAdapter (this, getData (),
R. layout. main, new String []
{"Title", "info", "img"}, new int []
{R. id. title, R.id.info, R. id. img });
SetListAdapter (adapter );
}
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 1 ");
Map. put ("img", R. drawable. icon );
List. add (map );
Map = new HashMap <String, Object> ();
Map. put ("title", "G2 ");
Map. put ("info", "google 2 ");
Map. put ("img", R. drawable. icon );
List. add (map );
Map = new HashMap <String, Object> ();
Map. put ("title", "G3 ");
Map. put ("info", "google 3 ");
Map. put ("img", R. drawable. icon );
List. add (map );
Return list;
}
}
Public class ListViewActivity extends ListActivity
{
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
// SetContentView (R. layout. main );
SimpleAdapter adapter = new SimpleAdapter (this, getData (),
R. layout. main, new String []
{"Title", "info", "img"}, new int []
{R. id. title, R.id.info, R. id. img });
SetListAdapter (adapter );
}
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 1 ");
Map. put ("img", R. drawable. icon );
List. add (map );
Map = new HashMap <String, Object> ();
Map. put ("title", "G2 ");
Map. put ("info", "google 2 ");
Map. put ("img", R. drawable. icon );
List. add (map );
Map = new HashMap <String, Object> ();
Map. put ("title", "G3 ");
Map. put ("info", "google 3 ");
Map. put ("img", R. drawable. icon );
List. add (map );
Return list;
}
}
[Java]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<RelativeLayout
Android: orientation = "vertical"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
<ImageView
Android: id = "@ + id/img"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_margin = "2px"/>
<TextView
Android: id = "@ + id/title"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_toRightOf = "@ id/img"
Android: textColor = "# FFFFFFFF"
Android: textSize = "22px"/>
<TextView
Android: id = "@ + id/info"
Android: layout_toRightOf = "@ id/img"
Android: layout_alignBottom = "@ id/img"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textColor = "# FFFFFFFF"
Android: textSize = "13px"/>
</RelativeLayout>
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<RelativeLayout
Android: orientation = "vertical"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
<ImageView
Android: id = "@ + id/img"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_margin = "2px"/>
<TextView
Android: id = "@ + id/title"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_toRightOf = "@ id/img"
Android: textColor = "# FFFFFFFF"
Android: textSize = "22px"/>
<TextView
Android: id = "@ + id/info"
Android: layout_toRightOf = "@ id/img"
Android: layout_alignBottom = "@ id/img"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textColor = "# FFFFFFFF"
Android: textSize = "13px"/>
</RelativeLayout>
</LinearLayout>
The setListAdapter () method is available in ListActivity.
// The selected logic of an item in ListView www.2cto.com
[Java]
<Pre name = "code" class = "java"> @ Override
Protected void onListItemClick (ListView l, View v, int position, long id)
{
Log. v ("MyListView4-click", (String) mData. get (position). get ("title "));
}
<Pre name = "code" class = "java"> @ Override
Protected void onListItemClick (ListView l, View v, int position, long id)
{
Log. v ("MyListView4-click", (String) mData. get (position). get ("title "));
}
From running snails