我是多人编程的新手。如何设置String
为 hashmap 值?我想从 RoomListActivity 调用 hashmap 属性并将其设置为 QuizMaintain 活动的值,并且我想将 QuizMaintain 类中的 hashmap 值设置为 textview。这是我的示例代码
房间列表活动
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);
}
我想设置哈希图值,关键是“问题”。我要设置的值来自拆分字符串。当我询问他们的支持团队是否要获取房间属性时,我应该调用 getLiveRoomInfo 方法并将 roomID 作为参数传递。这里有点糊涂。谢谢。
但似乎我的问题还没有解决。在调用方法 updateRoomProperties 之后,我在这里遇到了另一个错误。据说 WarpClient.AddZoneRequestListener(this) 返回空指针异常