登录用户对话请求列表

用于从登录用户的 Quickblox 服务器接收聊天对话框的代码(使用 listview 的示例)

private void receiveChatList() {
QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();
requestBuilder.setLimit(100);

QBRestChatService.getChatDialogs(null, requestBuilder).performAsync(
        new QBEntityCallback<ArrayList<QBChatDialog>>() {
            @Override
            public void onSuccess(final ArrayList<QBChatDialog> result, Bundle params) {
                int totalEntries = params.getInt("total_entries");
                Log.wtf("chat",""+result);
                TrumeMsgAdapter adapter=new TrumeMsgAdapter(this,result);
                chatlistView.setAdapter(adapter);
                chatlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        startActivity(new Intent(this,ChatingActivity.class).putExtra("dialog",result.get(position)));
                    }
                });

            }
            @Override
            public void onError(QBResponseException responseException) {

            }
        });

}

适配器代码: -

    public class TrumeMsgAdapter extends BaseAdapter {

private ArrayList<QBChatDialog> chatlist;
private Context context;

public TrumeMsgAdapter(Context c,ArrayList<QBChatDialog> chatlist){
    this.chatlist=chatlist;
    this.context=c;
}
@Override
public int getCount() {
    return chatlist.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View List;
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        List = inflater.inflate(R.layout.trume_msg_adapter, null);
        TextView username=(TextView) List.findViewById(R.id.UserName);
        TextView lastmessage=(TextView)List.findViewById(R.id.lastmessage);
        username.setText(chatlist.get(position).getName());
        lastmessage.setText(chatlist.get(position).getLastMessage());
    } else {
        List = convertView;
        TextView username=(TextView) List.findViewById(R.id.UserName);
        TextView lastmessage=(TextView)List.findViewById(R.id.lastmessage);
        username.setText(chatlist.get(position).getName());
        lastmessage.setText(chatlist.get(position).getLastMessage());
    }

    return List;
}
}