本文介绍了无法显示onItemClick()的Toast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我,请告诉我下面的代码如何在烤面包中显示房间ID.下面的代码正常工作,但是我无法在Toast中显示RoomId.
Some One Can Help Me Please Told Me How To Show Room Id In Toast Below Is The Code. Below Code Working But I am Not Able To Show RoomId in Toast.
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;
}
请帮助我如何在吐司中显示房间ID
Please Please Help Me How to Show Room Id In TOast
推荐答案
替换
Toast.makeText(getApplicationContext(),
"Position :"+itemPosition, Toast.LENGTH_LONG)
.show();
使用
Toast.makeText(RoomListActivity.this,
"Position :"+itemPosition, Toast.LENGTH_LONG)
.show();
这篇关于无法显示onItemClick()的Toast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!