2
Hello, I would like to know how I can show 10 items per page in listview?
Adapter:
ThreadsAdapter(@NonNull Context context, int resource, @NonNull List<MessageThread> objects, ThreadsActivity threadsActivity, Query ordenar) {
super(context, resource, objects);
this.ctx = context;
this.dataUpdateAfterDelete=threadsActivity;
this.messageThreadObjects = (ArrayList<MessageThread>) objects;
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
user = mAuth.getCurrentUser();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
currentUserId = mAuth.getCurrentUser().getUid();
}
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
messageThread = getItem(position);
ThreadsAdapter.ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.threads_listview, parent, false);
viewHolder = new ViewHolder();
viewHolder.threadTitleTV = convertView.findViewById(R.id.threadTitleTV);
viewHolder.nombretema = convertView.findViewById(R.id.nombretema);
viewHolder.messagethreadsTimeTV = convertView.findViewById(R.id.messagethreadsTimeTV);
viewHolder.numCommentsTV = convertView.findViewById(R.id.numCommentsTV);
viewHolder.deleteThreadButton = convertView.findViewById(R.id.deleteThreadButton);
viewHolder.comentariosTV = convertView.findViewById(R.id.comentariosTV);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (!messageThread.user_id.equals(mAuth.getCurrentUser().getUid())) {
viewHolder.deleteThreadButton.setVisibility(View.INVISIBLE);
} else {
viewHolder.deleteThreadButton.setVisibility(View.VISIBLE);
}
viewHolder.nombretema.setText(messageThread.user_name);
viewHolder.threadTitleTV.setTextColor(Color.parseColor("#000000"));
viewHolder.threadTitleTV.setText(messageThread.title);
Activity :
public void getThreads() {
mDatabase.child("Normas").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Query ordenar = mDatabase.child("Normas").orderByChild("countthreads");
threadsList.clear();
for (DataSnapshot messageThreadSnapshot : dataSnapshot.getChildren()) {
Query ordenar1 = mDatabase.child("Normas").orderByChild("countthreads");
MessageThread messageThread = messageThreadSnapshot.getValue(MessageThread.class);
if (messageThread != null) {
messageThread.thread_id = messageThreadSnapshot.getKey();
Log.d(TAG, "onDataChange: " + messageThread.toString());
}
threadsList.add(messageThread);
}
threadsAdapter = new ThreadsAdapter(ThreadsActivity.this, R.layout.threads_listview, threadsList, ThreadsActivity.this, ordenar);
Collections.reverse(threadsList);
threadsListView.setAdapter(threadsAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(ThreadsActivity.this, "ThreadsActivity: " + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});