[英]Updating table layout content as I insert more rows
I have two tables ( pendingTable
and approvedTable
) that contain rows of pending and approved transactions.我有两个表(
pendingTable
和approvedTable
),其中包含待处理和已批准事务的行。 I'm reading the data from Firestore and onComplete
I display these transactions in the tableViews
, for some reason I can't update the tables as I process the rows, for example: I have 10 transactions, I retrieve them sorted from the Firestore DB, I call a function that inflates a table row view and inserts the data into it and after that, I add the returned row to the table.我正在从 Firestore 和
onComplete
读取数据我在tableViews
中显示这些事务,由于某种原因我无法在处理行时更新表,例如:我有 10 个事务,我从 Firestore DB 中检索它们排序,我调用一个 function 来膨胀表行视图并将数据插入其中,然后将返回的行添加到表中。
What happens is only after I process all the 10 transactions and get all the rows, they are displayed to the screen, but I want as I process them, to display the ready rows so the table will be updating as I process the rows.只有在我处理完所有 10 个事务并获取所有行之后,它们才会显示在屏幕上,但我希望在处理它们时显示准备好的行,以便在处理行时表将更新。
I tried using threads but it's also not working.我尝试使用线程,但它也不起作用。 calling
postInvalidate();
调用
postInvalidate();
or refreshDrawableState();
或
refreshDrawableState();
also doesn't work.也不起作用。
Here are my functions:这是我的功能:
branchReference.collection("Actions")
.orderBy("date", Query.Direction.DESCENDING)
.limit(DISPLAYED_ACTIONS)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful()){
int i = 0, j = 0;
for(QueryDocumentSnapshot document : task.getResult()){
Action action = document.toObject(Action.class);
if(action.isPending()){
pendingTable.addView(actionRow(action, document.getReference(), j++));
} else {
approvedTable.addView(actionRow(action, document.getReference(), i++));
}
}
} else {
//Error handling
}
}
});
actionRow function is just creating a row and adding data to it then returns it actionRow function 只是创建一行并向其中添加数据然后返回它
If it's not possible, how can I make it looks more smooth and faster?如果不可能,我怎样才能让它看起来更流畅和更快?
According to the official documentation of getting data from Firestore , when you are using a "get()" call, it means that you are getting the data exactly once.根据 从 Firestore 获取数据的官方文档,当您使用“get()”调用时,这意味着您只获取了一次数据。 That's the reason why when you add new data, is not added to your view.
这就是为什么当您添加新数据时,不会将其添加到您的视图中。 If you want to get the data in real-time for every change that takes place, then you should listen for real-time updates .
如果您想实时获取发生的每个更改的数据,那么您应该收听实时更新。
There is also a library that can help y ou achieve that, which is called Firebase-UI for Android .还有一个库可以帮助您实现这一目标,它被称为Firebase-UI for Android 。 So check the documentation, as it has a really easy implementation.
因此,请查看文档,因为它的实现非常简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.