有人可以帮助我请告诉我如何在下面的吐司中显示房间ID是代码。下面的代码工作,但我不能在Toast中显示RoomId。
JSONArray rooms = jsonObject.getJSONArray("rooms");
for (int i = 0; i < rooms.length(); i++) {
JSONObject room = rooms.getJSONObject(i);
System.out.println("List Room Query".toString());
System.out.println(room.toString());
String rname = room.optString("room");
String rnameid = room.optString("roomid");
String outPut2 = rnameid;
ListView listView = (ListView) findViewById(R.id.ChatlistView);
SimpleAdapter simpleAdapter = new SimpleAdapter(RoomListActivity.this, roomList, android.R.layout.simple_list_item_1, new String[] {"chatroom"}, new int[] {android.R.id.text1});
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int itemPosition = position;
Toast.makeText(getApplicationContext(), "Position :"+itemPosition, Toast.LENGTH_LONG).show();
}
});
}
以下是哈希
List<Map<String,String>> roomList = new ArrayList<Map<String,String>>();
private HashMap<String, String>createRoom(String name,String number){
HashMap<String, String> roomName = new HashMap<String, String>();
roomName.put(name, number);
return roomName;
}
请帮助我如何在Toast中显示房间ID
答案 0 :(得分:-3)
替换
Toast.makeText(getApplicationContext(),
"Position :"+itemPosition, Toast.LENGTH_LONG)
.show();
与
Toast.makeText(RoomListActivity.this,
"Position :"+itemPosition, Toast.LENGTH_LONG)
.show();