@Override public Fragment getItem(int i) { Fragment fragment = null; switch (i) { case 0: mMainConversationTv.setTextColor(getResources().getColor(R.color.de_title_bg)); // TODO if (mConversationFragment == null) { ConversationListFragment listFragment = ConversationListFragment.getInstance(); listFragment.setAdapter(new ConversationListAdapterEx(RongContext.getInstance())); Uri uri = Uri.parse("rong://" + getApplicationInfo().packageName) .buildUpon() .appendPath("conversationlist") .appendQueryParameter( Conversation.ConversationType.PRIVATE.getName(), "false") // 设置私聊会话是否聚合显示 .appendQueryParameter( Conversation.ConversationType.GROUP.getName(), "false") // 群组 .appendQueryParameter( Conversation.ConversationType.DISCUSSION.getName(), "false") // 讨论组 .appendQueryParameter( Conversation.ConversationType.PUBLIC_SERVICE.getName(), "false") // 公共服务号 .appendQueryParameter( Conversation.ConversationType.SYSTEM.getName(), "false") // 系统 .build(); listFragment.setUri(uri); fragment = listFragment; } else { fragment = mConversationFragment; } break; case 1: if (mGroupListFragment == null) { mGroupListFragment = new GroupListFragment(); } fragment = mGroupListFragment; break; case 2: if (mChatroomFragment == null) { fragment = new ChatRoomListFragment(); } else { fragment = mChatroomFragment; } break; case 3: if (mCustomerFragment == null) { fragment = new CustomerFragment(); } else { fragment = mCustomerFragment; } break; } return fragment; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rong_activity); ConversationListFragment fragment = new ConversationListFragment(); Uri uri = Uri.parse("rong://" + getApplicationInfo().packageName) .buildUpon() .appendPath("conversationlist") .appendQueryParameter( Conversation.ConversationType.PRIVATE.getName(), "true") // 设置私聊会话是否聚合显示 .appendQueryParameter(Conversation.ConversationType.GROUP.getName(), "true") .appendQueryParameter(Conversation.ConversationType.DISCUSSION.getName(), "false") .appendQueryParameter(Conversation.ConversationType.SYSTEM.getName(), "true") .build(); fragment.setUri(uri); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // xxx 为你要加载的 id transaction.add(R.id.rong_content, fragment); transaction.commit(); }