我使用firebase数据库作为后端创建了一个聊天应用程序。 我想向在应用程序中注册的所有用户显示启动该应用程序的任何用户,除了在用户列表中显示他或她的名字。
我使用过FirebaseListAdapter,一个ListView和单用户布局。 这是源代码。我将所有用户都放在一个单独的线程中。
我尝试重写isEnabled方法虽然它不起作用。它只会禁用与查看当前用户列表的用户对应的列表项。
private class LoadFriends extends Thread{
ChatHomeActivity chatHomeActivity;
int pos;
public LoadFriends(ChatHomeActivity chatHomeActivity) {
this.chatHomeActivity = chatHomeActivity;
}
@Override
public void run() {
super.run();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE);
}
});
final FirebaseListAdapter<UserDetailsClass> adapter = new FirebaseListAdapter<UserDetailsClass>(chatHomeActivity,UserDetailsClass.class,R.layout.friend_online,tempUserRef) {
// @Override
// protected void populateView(View v, User model, int position) {
//
// TextView t = (TextView) v.findViewById(R.id.textView3);
// TextView online_offline = (TextView) v.findViewById(R.id.textView4);
// String uID = model.getUniqueID();
//
// if(uID.equals(UserDetails.getString("UniqueID","ID"))){
// sender = model.getName();
// v.setVisibility(View.GONE);
// }
// if(!uID.equals(UserDetails.getString("UniqueID","ID"))){
// t.setText(model.getName());
// int x= model.getOnline();
//
// if(x == 0){
// online_offline.setText(" ");
// online_offline.setTextColor(Color.RED);
// }
// if (x == 1){
// online_offline.setText("Online");
// online_offline.setTextColor(Color.GREEN);
// }
// v.setVisibility(View.VISIBLE);
// }
// }
@Override
protected void populateView(View v, UserDetailsClass model, int position) {
TextView t = (TextView) v.findViewById(R.id.textView3);
TextView online_offline = (TextView) v.findViewById(R.id.textView4);
String uID = model.getUserID();
if(uID.equals(UserDetails.getString("UniqueID","ID"))){
sender = model.getName();
v.setVisibility(View.GONE);
pos = position;
//isEnabled(position);
//v.setLayoutParams(new AbsListView.LayoutParams(0, 0));
}
if(!uID.equals(UserDetails.getString("UniqueID","ID"))){
t.setText(model.getName());
int x= model.getOnline_offline_status();
if(x == 0){
online_offline.setText(" ");
online_offline.setTextColor(Color.RED);
}
if (x == 1){
online_offline.setText("Online");
online_offline.setTextColor(Color.GREEN);
}
v.setVisibility(View.VISIBLE);
//areAllItemsEnabled();
}
}
@Override
public boolean isEnabled(int position) {
if (position!= pos){
return true;
}
return super.isEnabled(position);
}
// @Override
// public boolean areAllItemsEnabled() {
// return true;
// }
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
};
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
}
});
}
}