地狱所有......我正在努力使用这个简单的聊天应用...我正在练习.....我无法让聊天列表自动刷新...只有这样我才能看到我发送的最新消息是关闭应用程序并重新打开...
`
ListView listView;
ArrayAdapter<String>listloader;
TextView editmsg;
Button convosend;
private static Handler handler;
@Override
public void onCreate(Bundle savedInstanceState)
{
Parse.enableLocalDatastore(this);
Parse.initialize(this, "", "");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText editmsg=(EditText)findViewById(R.id.editmsg);
final Button convosend=(Button)findViewById(R.id.convosend);
final ListView listView=(ListView)findViewById(R.id.listView);
getActionBar().setTitle("Cyber chat");
handler =new Handler();
convosend.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//button send
String msg= editmsg.getText().toString();
ParseObject users = new ParseObject("Users");
users.put("name", "mckeny");
users.put("age", "26");
users.put("gender", msg);
users.saveEventually();
}}); handler.postDelayed(new Runnable()
{
@Override
public void run()
{
ParseQuery <ParseObject> q=ParseQuery.getQuery("Users");
q.setLimit(30);
q.orderByDescending("createdAt");
q.whereEqualTo("name","mckeny");
q.findInBackground(new FindCallback<ParseObject>()
{
@Override
public void done(List<ParseObject>u,ParseException e)
{
ArrayList<String>list =new ArrayList<String>();
for(ParseObject user:u)
{
list.add(user.getString("name"));
list.add(user.getString("gender"));}
listloader = new ArrayAdapter(MainActivity.this,R.layout.list,list);
listloader.notifyDataSetChanged();
listView.setAdapter(listloader);
}
});
}},1000);
}}
答案 0 :(得分:0)
要立即查看最新消息而无需关闭然后再打开应用程序,则需要设置和使用消息侦听器。这是一个如何在ConnectyCube聊天中实现接收消息的示例:
IncomingMessagesManager incomingMessagesManager = chatService.getIncomingMessagesManager();
incomingMessagesManager.addDialogMessageListener(new ChatDialogMessageListener() {
@Override
public void processMessage(String dialogId, ConnectycubeChatMessage message, Integer senderId) {
}
@Override
public void processError(String dialogId, ChatException exception, ConnectycubeChatMessage message, Integer senderId) {
}
});