实际上,我想在 textview 或 listview 中显示朋友列表中的名称,请建议任何好的方法来表示它。我使用了以下代码,但它不起作用。确切地说,我正在寻找解决方案来显示具有在线离线状态的好友列表。请帮助我。
public void connect() {
final ProgressDialog dialog = ProgressDialog.show(this,
"Connecting...", "Please wait...", false);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// Create a connection
ConnectionConfiguration connConfig = new ConnectionConfiguration(
HOST, PORT, SERVICE);
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
Log.i("XMPPChatDemoActivity",
"Connected to " + connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPPChatDemoActivity", "Failed to connect to "
+ connection.getHost());
Log.e("XMPPChatDemoActivity", ex.toString());
}
try {
// SASLAuthentication.supportSASLMechanism("PLAIN", 0);
connection.login(USERNAME, PASSWORD);
Log.i("XMPPChatDemoActivity",
"Logged in as " + connection.getUser());
// Set the status to available
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
sb = new StringBuffer();
for (RosterEntry entry : entries) {
Presence entryPresence = roster.getPresence(entry
.getUser());
String number1 = entry.getUser();
String name1 = entry.getName();
String status = entryPresence.getStatus();
String TYpe;
Presence.Type type = entryPresence.getType();
if (type == Presence.Type.available){
TYpe="available";
}else{
TYpe="unavailable";
}
sb.append( "\nName:---"+number1 );
Log.e(number1, "names");
sb.append("\n----------------------------------");
}
name.setText(sb);
}
catch (XMPPException ex) {
Log.e("XMPPChatDemoActivity", "Failed to log in as "
+ USERNAME);
Log.e("XMPPChatDemoActivity", ex.toString());
}
dialog.dismiss();
}
});
t.start();
dialog.show();
}
}