Main.xml
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
Tools:context= ". Mainactivity ">
<listview
Android:id= "@+id/listview1"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:layout_centerhorizontal= "true"
Android:layout_centervertical= "true" >
</ListView>
</RelativeLayout>
Item.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:layout_height= "Fill_parent"
Android:layout_width= "Fill_parent" >
<imageview
Android:layout_alignparentright= "true"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/itemimage"/>
<textview
Android:id= "@+id/itemtitle"
android:layout_height= "Wrap_content"
Android:layout_width= "Fill_parent"
Android:textsize= "20sp"/>
<textview
Android:id= "@+id/itemtext"
android:layout_height= "Wrap_content"
Android:layout_width= "Fill_parent"
android:layout_below= "@+id/itemtitle"/>
</RelativeLayout>
Main code
public class Mainactivity extends Activity {
Private ListView ListView;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
ListView = (ListView) This.findviewbyid (R.id.listview1);
arraylist
for (int i = 0; i < i++) {
hashmap<string, object> map = new hashmap<string, object> ();
Map.put ("title", "title" + i);
Map.put ("Content", "contents" + i);
Map.put ("Image", R.drawable.ic_launcher);
Lst.add (map);
}
Simpleadapter simpleadapter = new Simpleadapter (this, LST,
R.layout.item, new string[] {"Title", "Content", "Image"},
New int[] {r.id.itemtitle, r.id.itemtext, r.id.itemimage});
Listview.setadapter (Simpleadapter);
Listview.setonitemclicklistener (New Onitemclicklistener () {
@Override
public void Onitemclick (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
TODO auto-generated Method Stub
Toast.maketext (mainactivity.this, "dot" +arg3, +). Show ();
}
});
}
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu);
return true;
}
}