I'm having trouble sharing data between android and nodejs server.
When nodejs server emits data to android, i wanna put this data into edittext by using setText() but it doesn't work.... please help me!!
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button1);
editText1 = (EditText)findViewById(R.id.editText1);
editText2 = (EditText)findViewById(R.id.editText2);
socket_initialize();
button.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
socket.emit("adr_msg", editText2.getText().toString());
}
});
}
private void socket_initialize() {
// TODO Auto-generated method stub
try {
socket = new SocketIO("http://192.168.219.100:3000");
socket.connect(new IOCallback(){
public void on(String arg0, IOAcknowledge arg1, Object... arg2) {
// TODO Auto-generated method stub
if("gogo".equals(arg0)){
Log.d("see this:","working");
}
else if("serv_msg".equals(arg0)){
//Toast.makeText(getApplicationContext(), "working: "+arg2[0].toString(), Toast.LENGTH_SHORT).show();
Log.d("testing : ",arg2[0].toString());
--> editText1.setText(arg2[0].toString());
// this code occurs an error!
}
}
0 comments:
Post a Comment