package com.fanxin.huangfangyi.ui; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import com.fanxin.easeui.domain.EaseUser; import com.fanxin.easeui.utils.EaseUserUtils; import com.hyphenate.chat.EMClient; import com.hyphenate.chat.EMGroup; import com.fanxin.huangfangyi.R; import com.fanxin.easeui.adapter.EaseContactAdapter; public class PickAtUserActivity extends BaseActivity { @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.activity_pick_at_user); String groupId = getIntent().getStringExtra("groupId"); EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId); final ListView listView = (ListView) findViewById(R.id.list); List<String> members = group.getMembers(); List<EaseUser> userList = new ArrayList<EaseUser>(); for(String username : members){ EaseUser user = EaseUserUtils.getUserInfo(username); userList.add(user); } Collections.sort(userList, new Comparator<EaseUser>() { @Override public int compare(EaseUser lhs, EaseUser rhs) { if(lhs.getInitialLetter().equals(rhs.getInitialLetter())){ return lhs.getNick().compareTo(rhs.getNick()); }else{ if("#".equals(lhs.getInitialLetter())){ return 1; }else if("#".equals(rhs.getInitialLetter())){ return -1; } return lhs.getInitialLetter().compareTo(rhs.getInitialLetter()); } } }); listView.setAdapter(new PickUserAdapter(this, 0, userList)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EaseUser user = (EaseUser) listView.getItemAtPosition(position); if(EMClient.getInstance().getCurrentUser().equals(user.getUsername())) return; setResult(Activity.RESULT_OK, new Intent().putExtra("username", user.getUsername())); finish(); } }); } private class PickUserAdapter extends EaseContactAdapter{ public PickUserAdapter(Context context, int resource, List<EaseUser> objects) { super(context, resource, objects); } } }