Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DisplayAllData extends RecyclerView.Adapter<DisplayAllData.ItemViewHolder>{
- private List<User> mUserLsit=new ArrayList<>();
- private Context mContext;
- @Override
- public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout,parent,false);
- return new ItemViewHolder(view);
- }
- public DisplayAllData(Context mContext,List<User> mUserLsit) {
- this.mContext=mContext;
- this.mUserLsit = mUserLsit;
- }
- @Override
- public void onBindViewHolder(ItemViewHolder holder, int position) {
- User user=mUserLsit.get(position);
- holder.mTvName.setText(user.name);
- holder.mTvEmail.setText(user.email);
- holder.mTvPwd.setText(user.pwd);
- }
- @Override
- public int getItemCount() {
- return mUserLsit.size();
- }
- public class ItemViewHolder extends RecyclerView.ViewHolder {
- TextView mTvName,mTvEmail,mTvPwd;
- public ItemViewHolder(View itemView) {
- super(itemView);
- mTvEmail=itemView.findViewById(R.id.rlTvEmail);
- mTvName=itemView.findViewById(R.id.rlTvName);
- mTvPwd=itemView.findViewById(R.id.rlTvPwd);
- }
- }
- }
- public class DisplayActivity extends AppCompatActivity {
- private RecyclerView mRvData;
- private DisplayAllData allDataAdapter;
- private DatabaseReference mDatabase;
- private TextView mTvEmpty;
- private FirebaseDatabase mFirebaseInstance;
- private List<User> mUserList = new ArrayList<>();
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.display_data);
- initView();
- }
- private void initView() {
- mFirebaseInstance = FirebaseDatabase.getInstance();
- mDatabase = mFirebaseInstance.getReference("usersDb/UserTable");
- mRvData = findViewById(R.id.rvData);
- mTvEmpty = findViewById(R.id.dlTvEmpty);
- mRvData.setLayoutManager(new LinearLayoutManager(this));
- mDatabase.addValueEventListener(new ValueEventListener() {
- @Override
- public void onDataChange(DataSnapshot dataSnapshot) {
- mUserList.clear();
- for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
- User user = dataSnapshot1.getValue(User.class);
- mUserList.add(user);
- }
- allDataAdapter = new DisplayAllData(DisplayActivity.this, mUserList);
- mRvData.setAdapter(allDataAdapter);
- allDataAdapter.notifyDataSetChanged();
- if (mUserList.isEmpty())
- mTvEmpty.setVisibility(View.VISIBLE);
- else
- mTvEmpty.setVisibility(View.GONE);
- }
- @Override
- public void onCancelled(DatabaseError databaseError) {
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment