Item. xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="1dp" android:paddingBottom="1dp" xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:id="@+id/scoreId" android:layout_width="60dip" android:layout_height="30dip" android:textSize="10pt" android:singleLine="true"/> <TextView android:id="@+id/userName" android:layout_width="80dip" android:layout_height="30dip" android:textSize="10pt" android:singleLine="true"/> <TextView android:id="@+id/userScore" android:layout_width="80dip" android:layout_height="30dip" android:textSize="10pt" android:singleLine="true"/> </LinearLayout>
Scorelist. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Xmlns: Android = "http://schemas.android.com/apk/res/android">
<Linearlayout
Android: Id = "@ + ID/listlinearlayout"
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
<Listview
Android: Id ="@ + ID/listview"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
</Linearlayout>
</Linearlayout>
Public classScorelistactivityExtendsActivity{
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. scorelist );
Listview = (listview) findviewbyid (R. Id. listview );
Scoredao = new scoredao (scorelistactivity. This );
List <userscore> userscores = scoredao. getallscore ();
Arraylist For (userscore: userscores ){
Hashmap <string, Object> map = new hashmap <string, Object> ();
Map. Put ("scoreid", userscore. GETID ());
Map. Put ("username", userscore. GetUserName ());
Map. Put ("userscore", userscore. getuserscore ());
List. Add (MAP );
}
Simpleadapter adapter = new simpleadapter (scorelistactivity. This,
List, R. layout. Item, new string [] {"scoreid", "username", "userscore "},
New int [] {R. Id. scoreid, R. Id. username, R. Id. userscore });
Listview. setadapter (adapter );
Listview. setonitemclicklistener (New onitemclicklistener (){
@ Override
Public void onitemclick (adapterview <?> Parent, view,
Int position, long ID ){
// Parent is the clicked listview.
Listview = (listview) parent;
Hashmap <string, Object> item = (hashmap <string, Object>) listview. getitematposition (position );
// Obtain the ID of the selected row
Object scoreid = item. Get ("scoreid ");
Toast. maketext (scorelistactivity. This, scoreid. tostring (), Toast. length_long). Show ();
}
});
}
}