public void onEventMainThread(UserInfo userInfo) {
    int count = mAdapter.getCount();

    for (int i = 0; i < count; i++) {
      UserInfo temp = mAdapter.getItem(i);
      if (userInfo.getUserId().equals(temp.getUserId())) {
        temp.setName(userInfo.getName());
        temp.setPortraitUri(userInfo.getPortraitUri());
        mAdapter.getView(
            i, mGridList.getChildAt(i - mGridList.getFirstVisiblePosition()), mGridList);
      }
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent;

    RongContext.getInstance().getEventBus().register(this);

    if (getActivity() != null) {

      intent = getActivity().getIntent();

      if (intent.getData() != null) {

        mConversationType =
            Conversation.ConversationType.valueOf(
                intent.getData().getLastPathSegment().toUpperCase());

        mTargetId = intent.getData().getQueryParameter("targetId");
      }
    }
    mAdapter = new RongConversationAddMemberAdapter(getActivity());
    mAdapter.setDeleteIconListener(this);

    if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) {
      initData();
    }
  }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   UserInfo userInfo = mAdapter.getItem(position);
   if (userInfo.getUserId().equals("RongDelBtn")) {
     mAdapter.setDeleteState(true);
     int count = mAdapter.getCount();
     mAdapter.remove(count - 1);
     mAdapter.remove(count - 2);
     mAdapter.notifyDataSetChanged();
   } else if (userInfo.getUserId().equals("RongAddBtn")) {
     if (RongContext.getInstance().getMemberSelectListener() == null) {
       throw new ExceptionInInitializerError("The OnMemberSelectListener hasn't been set!");
     }
     RongContext.getInstance()
         .getMemberSelectListener()
         .startSelectMember(getActivity(), mConversationType, mTargetId);
   }
 }
  @Override
  public void onDeleteIconClick(View view, final int position) {
    UserInfo temp = mAdapter.getItem(position);
    RongIM.getInstance()
        .getRongIMClient()
        .removeMemberFromDiscussion(
            mTargetId,
            temp.getUserId(),
            new RongIMClient.OperationCallback() {
              @Override
              public void onSuccess() {
                Message msg = new Message();
                msg.what = REMOVE_ITEM;
                msg.obj = position;
                getHandler().sendMessage(msg);
              }

              @Override
              public void onError(RongIMClient.ErrorCode errorCode) {
                getHandler().sendEmptyMessage(SHOW_TOAST);
              }
            });
  }
  @Override
  public boolean handleMessage(android.os.Message msg) {
    switch (msg.what) {
      case PREPARE_LIST:
        List<String> mMemberInfo = (List<String>) msg.obj;
        int i = 0;
        for (String id : mMemberInfo) {
          if (i < 50) {
            UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(id);
            if (userInfo == null) {
              mMembers.add(new UserInfo(id, null, null));
            } else mMembers.add(userInfo);
          } else {
            break;
          }

          i++;
        }
        UserInfo addBtn = new UserInfo("RongAddBtn", null, null);
        mMembers.add(addBtn);

        String curUserId = RongIM.getInstance().getRongIMClient().getCurrentUserId();
        if (mAdapter.getCreatorId() != null
            && mConversationType.equals(Conversation.ConversationType.DISCUSSION)
            && curUserId.equals(mAdapter.getCreatorId())) {
          UserInfo deleteBtn = new UserInfo("RongDelBtn", null, null);
          mMembers.add(deleteBtn);
        }

        mAdapter.addCollection(mMembers);
        mAdapter.notifyDataSetChanged();
        break;
      case REMOVE_ITEM:
        int position = (Integer) msg.obj;
        mAdapter.remove(position);
        mAdapter.notifyDataSetChanged();
        break;
      case SHOW_TOAST:
        break;
    }
    return true;
  }