Node.js and Websocket in Android Eclipse

前端 未结 1 1828
情话喂你
情话喂你 2020-12-19 21:43

Thanks for looking into my question.

I am a beginner in android development and currently i am trying to make chat app which uses socket and node js.

I use

1条回答
  •  囚心锁ツ
    2020-12-19 22:10

    Hy Karan.. you are going in the right way mate. The only thing that is missing is the small snippet of code. Error here is that you set adapter in working thread. You can update views only from main thread. You have to move the portion of the background task that updates the ui onto the main thread. Just replace the code on:

    @Override
                public void on(String event, IOAcknowledge ack, Object... args)
    

    with:

    @Override
                public void on(String event, IOAcknowledge ack, Object... args) {
                    // TODO Auto-generated method stub
                    if(event.equals("new_client_message")){
                        Log.v("SocketIO", "new_client_message" + " " + args[0]);
                        rohan = args[0].toString();
                        System.out.println("admin" + " : " + " " + rohan);
    
                        runOnUiThread(new Runnable(){
    
                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                mListData.add("Admin" + " : " + " " + rohan);
                                mListData.notifyDataSetChanged();
                                lvList.setSelection(mListData.getCount() -1);
    
                            }
    
                        });
                    }
    

    here "new_client_message" is trigger from the server.. just replace with yours. For example in you case "new_message" is the trigger from your app to the server. Sorry for not a professional word but i hope it will help. Cheers

    0 讨论(0)
提交回复
热议问题