0

我是多人编程的新手。如何设置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) 返回空指针异常

4

1 回答 1

0

当您创建一个房间时,您正在传递一个哈希图。此哈希图在服务器上的房间内存储为 JSON 文档。AppWarp 称之为房间属性。

现在要检索这些属性,您必须调用 getLiveRoomInfo 方法。这将向您显示房间属性。在这里,您再次添加/更改一些键值。但是您还没有告诉服务器您正在更新这些房间属性。因此,您的更改仍然是本地的,并且仅限于功能范围。

因此,当您调用 getLiveRoomInfo 方法时,您不会看到更改,因为您尚未在服务器上更新它们。要在服务器上更新,您需要调用 updateRoomProperties 方法。在这种方法中,您可以添加或更改您的哈希图。

于 2014-10-30T06:34:52.057 回答