我是多人编程的新手。如何将String设置为哈希映射值?我想从RoomListActivity调用哈希图属性,并在QuizMaintain活动上设置它的值,我还想将哈希图的值从QuizMaintain类设置为textview。下面是我的示例代码
RoomListActivity
public void onJoinNewRoomClicked(View view){
progressDialog = ProgressDialog.show(this,"","Please wait...");
progressDialog.setCancelable(true);
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("timer", "");
properties.put("question", "");
properties.put("answer", "");
properties.put("foulanswer", "");
theClient.createRoom(""+System.currentTimeMillis(), "Yoshua", 2, properties);
}然后我想从QuizMaintain活动中设置它的值
public class QuizMaintain extends Activity implements RoomRequestListener, NotifyListener {
private WarpClient theClient;
private HashMap<String, Object> properties;
private TextView txttimer,txtquestion;
private String roomId = "";
private HashMap<String, User> userMap = new HashMap<String, User>();
String string="5x5#5x4#150:3#500:20#536+59";
String[] questions = string.split("#");
String question1 = questions[0];
String question2 = questions[1];
String question3 = questions[2];
String question4 = questions[3];
String question5 = questions[4];
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_maintain);
txttimer = (TextView)findViewById(R.id.timer);
txtquestion = (TextView)findViewById(R.id.questionview);
try{
theClient = WarpClient.getInstance();
}catch(Exception e){
e.printStackTrace();
}
theClient.getLiveRoomInfo("143680827");
Intent intent = getIntent();
roomId = intent.getStringExtra("roomId");
init(roomId);
//setquestionview();
}
private void init(String roomId){
if(theClient!=null){
theClient.addRoomRequestListener(this);
theClient.addNotificationListener(this);
theClient.joinRoom(roomId);
}
}
@Override
public void onGetLiveRoomInfoDone(LiveRoomInfoEvent event) {
properties = event.getProperties();
properties.put("question", question1);
}我想设置hashmap的值,其中的关键是“问题”。我想要设置的值来自split string.When,我询问他们的支持团队,如果我想获得房间属性,我应该调用getLiveRoomInfo方法,并将roomID作为参数传递。这里有点困惑。谢谢。
但是我的问题似乎还没有解决。在调用方法updateRoomProperties之后,但我在这里得到了另一个错误。假设WarpClient.AddZoneRequestListener(this)返回空指针异常
发布于 2014-10-30 14:34:52
当您创建一个房间时,您正在传递一个hashmap。此hashmap以JSON文档的形式存储在服务器上的房间中。AppWarp将其称为房间属性。
现在,要检索这些属性,您必须调用getLiveRoomInfo方法。这将向您显示房间属性。在这里,您将再次添加/更改一些键值。但是您还没有告诉服务器您正在更新这些房间属性。因此,您的更改仍然是局部的,并且过于局限于函数的范围。
因此,当您调用getLiveRoomInfo方法时,您将看不到这些更改,因为您尚未在服务器上更新它们。要在服务器上更新,需要调用updateRoomProperties方法。在此方法中,您可以添加或更改您的hashmap。
https://stackoverflow.com/questions/26643318
复制相似问题