Created
October 1, 2011 14:52
-
-
Save neufuture/1256137 to your computer and use it in GitHub Desktop.
Android ListView without ListActivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="wrap_content" | |
android:orientation="vertical"> | |
<TextView android:id="@+id/standingText" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"/> | |
<TextView android:id="@+id/scoreText" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"/> | |
<TextView android:id="@+id/userText" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"> | |
<ListView | |
android:id="@+id/leaderboard" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1"> | |
</ListView> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.ListView; | |
import android.widget.SimpleAdapter; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class MyCustomListView extends Activity{ | |
static final ArrayList<HashMap<String,String>> myList = | |
new ArrayList<HashMap<String,String>>(); | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
ListView leaderboard = (ListView) findViewById(R.id.leaderboard); | |
SimpleAdapter adapter = new SimpleAdapter( | |
this, | |
myList, | |
R.layout.leaderboard_item, | |
new String[] {"standing","score","user"}, | |
new int[] {R.id.standingText,R.id.scoreText, R.id.userText} | |
); | |
populateList(); | |
leaderboard.setAdapter(adapter); | |
} | |
private void populateList() { | |
HashMap<String,String> temp = new HashMap<String,String>(); | |
temp.put("standing","FIRST"); | |
temp.put("score", "2.4sec"); | |
temp.put("user", "daredevil"); | |
myList.add(temp); | |
temp.put("standing","SECOND"); | |
temp.put("score", "1.8sec"); | |
temp.put("user", "hardcoredropper"); | |
myList.add(temp); | |
temp.put("standing","THIRD"); | |
temp.put("score", "1.6sec"); | |
temp.put("user", "batman"); | |
myList.add(temp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment