我想根據帖子的時間戳對帖子進行排序。帖子包含標題和說明。我正在使用firebase來檢索數據。但是沒有任何東西顯示在視圖中。該視圖是空白的。有什麼我做錯了嗎?ViewHolder未顯示數據
public class AlertsActivity extends AppCompatActivity {
public static class BlogViewHolder extends RecyclerView.ViewHolder {
View mview;
public BlogViewHolder(View itemView) {
super(itemView);
mview = itemView;
}
public void setTitle(String title) {
TextView post_title = (TextView)mview.findViewById(R.id.blog_title);
post_title.setText(title);
}
public void setDesp(String desp) {
TextView post_desp = (TextView) mview.findViewById(R.id.blog_desp);
post_desp.setText(desp);
}
public void setTimestampCreated(HashMap<String, Object> timestamp) {
TextView show_ts = (TextView) mview.findViewById(blog_timestamp);
show_ts.setText(String.valueOf(timestamp));
}
}
適配器:
mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");
mDatabase.keepSynced(true);
mDatabase.orderByChild("timestamp");
FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter = new
FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.blog_row,
BlogViewHolder.class, mDatabase) {
@Override
protected void populateViewHolder(final BlogViewHolder viewHolder, final Blog model, int position) {
mDatabase.child("Blog").orderByChild("timestamp").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String alerts = dataSnapshot.getValue(String.class);
HashMap<String, Object> time = (HashMap<String, Object>) dataSnapshot.getValue();
viewHolder.setTitle(alerts);
viewHolder.setDesp(alerts);
viewHolder.setTimestampCreated(time);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
};
mbloglist.setAdapter(firebaseRecyclerAdapter);
}
數據庫的圖片: https://i.stack.imgur.com/GNouK.png
*有什麼我做錯了***的問題是:有什麼,你是正確的做法** ...你正在創建適配器內onProgressUpdate的異步任務,這是從來沒有使用過的,你的代碼不是格式化,並且cleary不完整 – Selvin
@Selvin我正在使用異步任務,以便進度條顯示。是的,我只展示了需要的重要部分。這不是完整的代碼 –
*我只顯示了所需的重要部分*,並且不會使敏感 – Selvin