Appwarp Android编程从房间列表活动获取属性

时间:2014-10-30 01:01:03

标签: android hashmap appwarp

我是多人游戏编程的新手。如何将String设置为hashmap值?我想从RoomListActivity调用hashmap属性并在QuizMaintain活动上设置它的值,我还想将hashmap值从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值,其中键是&#34;问题&#34;。我想要设置的值来自拆分字符串。当我问他们的支持团队是否要获得房间属性时,我应该调用getLiveRoomInfo方法并将roomID作为参数传递。这里有点困惑。感谢。

但似乎我的问题还没有解决。调用方法updateRoomProperties后,但我在这里得到了另一个错误。它说WarpClient.AddZoneRequestListener(this)返回空指针异常

1 个答案:

答案 0 :(得分:0)

当您创建房间时,您正在传递散列图。此hashmap作为JSON文档存储在服务器上的房间内。 AppWarp将其称为Room Properties。

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

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