ListAdapter from a HashMap

Pottsie

New Member
I'm trying to get my ArrayList of HashMaps to try to get a working ListAdapter. When I run this, I'm getting a \[code\]java.lang.RuntimeException: Your content must have a ListView whose id attribute is android.R.id.list\[/code\]error. Here's what I have:gameList is where I'm getting my data from: \[code\]gameList.toString() returns: [{turn=1, opponent=UserTwo, streak=4, hintX=1234, player=UserOne, solution=MySolution, hintY=5678}, {turn=0, opponent=UserThree, streak=12, hintX=1344, player=UserOne, solution=SolutionTwo, hintY=5428}]\[/code\]My ListActivity class:\[code\]public class GameListActivity extends ListActivity{@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.game_list); String GAME_ITEM = "game"; String PLAYER_ITEM = "player"; String OPPONENT_ITEM = "opponent"; String SOLUTION_ITEM = "solution"; String HINTX_ITEM = "hintX"; String HINTY_ITEM = "hintY"; String STREAK_ITEM = "streak"; String TURN_ITEM = "turn";ArrayList<HashMap<String, String>> gameList = new ArrayList<HashMap<String, String>>();AppVars gameVars = ((AppVars) getApplicationContext());gameList = gameVars.getState();String[] keyList = new String[] { OPPONENT_ITEM, STREAK_ITEM, TURN_ITEM };ListAdapter adapter = new SimpleAdapter(this, gameList, R.layout.game_list_item, keyList, new int[] {R.id.opponent, R.id.streak, R.id.turn});setListAdapter(adapter); } \[/code\]XML:game_list_item.xml:\[code\]<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp" > <ImageView android:id="@+id/thumbnail" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentTop="true" android:src="http://stackoverflow.com/questions/11056063/@android:drawable/alert_dark_frame" /> <TextView android:id="@+id/opponent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/thumbnail" android:layout_centerHorizontal="true" android:text="Entry" android:textSize="30sp" /> <TextView android:id="@+id/streak" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/thumbnail" android:layout_centerHorizontal="true" android:text="Streak" android:textSize="20sp" /> <TextView android:id="@+id/turn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/streak" android:layout_centerHorizontal="true" android:text="Your turn!" android:textSize="20sp" /></RelativeLayout>\[/code\]game_list.xml:\[code\]<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/blackboard" > <ListView android:id="@+id/gameList" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > </ListView></RelativeLayout>\[/code\]
 
Back
Top