- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Firebase Firestore 数据库
,我尝试使用此 Stackoverflow ans link 使用分页回收器数据的双重查询来加载数据。
我的代码用于recycerview
加载数据
private void getNewFireData() {
final int limit = 3;
final int mmcurrentItem;
final int totalItem;
final int ScrolledItem;
mRecyclerView = rootView.findViewById(R.id.rv_post_list);
final LinearLayoutManager mManeger=new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mManeger);
final List<Posts> list = new ArrayList<>();
final boolean[] isScrolling = {false};
final boolean[] isLastItemReached = {false};
final DocumentSnapshot lastVisible ;
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
final CollectionReference postRef = rootRef.collection("posts");
Query query = postRef.orderBy("datetime",
Query.Direction.DESCENDING).limit(limit);
query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful()){
final DocumentSnapshot[] lastVisible = {task.getResult().getDocuments().get(task.getResult().size() - 1)};
for (DocumentSnapshot document : task.getResult()) {
Posts postModel = document.toObject(Posts.class);
list.add(postModel);
}
final Task<QuerySnapshot>[] mSnapy = new Task[]{task};
final NewPostAdapter mNewPostAdapter = new NewPostAdapter(list,getActivity()
, mSnapy[0]);
mRecyclerView.setAdapter(mNewPostAdapter);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if(newState==AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
isScrolling[0] =true;
}
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) recyclerView.getLayoutManager());
int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
int visibleItemCount = linearLayoutManager.getChildCount();
int totalItemCount = linearLayoutManager.getItemCount();
if (isScrolling[0] && (firstVisibleItemPosition + visibleItemCount == totalItemCount) && !isLastItemReached[0]) {
isScrolling[0] = false;
Query nextQuery = postRef.orderBy("datetime", Query.Direction.DESCENDING).startAfter(lastVisible[0]).limit(limit);
nextQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> t) {
if (t.isSuccessful()) {
for (DocumentSnapshot d : t.getResult()) {
Posts productModel = d.toObject(Posts.class);
list.add(productModel);
mSnapy[0] =t;
}
mNewPostAdapter.notifyDataSetChanged();
lastVisible[0] = t.getResult().getDocuments().get(t.getResult().size() - 1);
if (t.getResult().size() < limit) {
isLastItemReached[0] = true;
}
}
}
});
}
}
});
}
}
});
}
View 持有者和适配器类是
public class NewPostAdapter extends RecyclerView.Adapter<NewPostAdapter.NewPostHolder> {
private List<Posts> list;
Context context;
Task<QuerySnapshot> task;
public NewPostAdapter(List<Posts> list, Context context, Task<QuerySnapshot> task) {
this.list = list;
this.context=context;
this.task=task;
}
@NonNull
@Override
public NewPostHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custum_home_post, parent, false);
return new NewPostHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final NewPostHolder mHolder, final int position) {
mHolder.tvSendername.setText(list.get(position).getSendername());
mHolder.tvPostText.setText(list.get(position).getPosttext());
mHolder.tvServiceType.setText(list.get(position).getServicetype());
String datetime = list.get(position).getDatetime();
MyDateTime myDateTime = new MyDateTime();
String converteddatetime = myDateTime.getSaveTime(datetime);
mHolder.tvDatetime.setText(converteddatetime);
SharedPreferences prefs = context.getSharedPreferences("DholkaAppPref", Context.MODE_PRIVATE);
String mUserid = prefs.getString("userid", "Couldn't load userid");
final String postid=task.getResult().getDocuments().get(position).getId();
if (mUserid.equalsIgnoreCase("LNvc0acRiaPioaKVnXasjkjEeYE2")) {
if (list.get(position).getVerified().equalsIgnoreCase("no")) {
mHolder.llPostAproval.setVisibility(View.VISIBLE);
mHolder.btPostApprove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (list.get(position).getVerified().equalsIgnoreCase("no")) {
PostApproval approval = new PostApproval(context, postid);
}
}
});
mHolder.btPostDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String imagename = list.get(position).getPhotourl();
if (imagename.equalsIgnoreCase("nourl")) {
DocumentReference mPostref = FirebaseFirestore.getInstance().collection("posts").
document(postid);
mPostref.delete();
} else {
StorageReference mStorageref = FirebaseStorage.getInstance().getReferenceFromUrl(imagename);
mStorageref.delete();
DocumentReference mPostref = FirebaseFirestore.getInstance().collection("posts").
document(postid);
mPostref.delete();
}
}
});
} else {
mHolder.llPostAproval.setVisibility(View.GONE);
mHolder.cardHome.setVisibility(View.VISIBLE);
}
} else {
mHolder.llPostAproval.setVisibility(View.GONE);
}
if (mUserid.equalsIgnoreCase("LNvc0acRiaPioaKVnXasjkjEeYE2")) {
mHolder.cardHome.setVisibility(View.VISIBLE);
mHolder.cardHome.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog dialog;
builder.setMessage(R.string.dialog_delete_post)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
String imagename = list.get(position).getPhotourl();
if (imagename.equalsIgnoreCase("nourl")) {
DocumentReference mPostref = FirebaseFirestore.getInstance().collection("posts").
document(postid);
mPostref.delete();
} else {
StorageReference mStorageref = FirebaseStorage.getInstance().getReferenceFromUrl(imagename);
mStorageref.delete();
DocumentReference mPostref = FirebaseFirestore.getInstance().collection("posts").
document(postid);
mPostref.delete();
}
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
dialog = builder.create();
dialog.show();
return false;
}
});
} else {
if (list.get(position).getVerified().equalsIgnoreCase("yes")) {
mHolder.cardHome.setVisibility(View.VISIBLE);
} else {
mHolder.cardHome.setVisibility(View.GONE);
}
}
String text = list.get(position).getPosttext();
if (text.length() > 150) {
text = text.substring(0, 150) + "...";
mHolder.tvPostText.setText(Html.fromHtml(text + "<font color='green'> <u>Read More</u></font>"));
mHolder.tvPostText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mHolder.tvPostText.setText(list.get(position).getPosttext());
}
});
} else {
mHolder.tvPostText.setText(list.get(position).getPosttext());
}
mHolder.tvTotalLike.setText("Likes : " + list.get(position).getTotal_like());
mHolder.tvTotalComments.setText("Comments : " + list.get(position).getTotal_comment());
final String photourl = list.get(position).getPhotourl();
if (photourl.equalsIgnoreCase("nourl")) {
mHolder.ivPostphoto.setVisibility(View.GONE);
} else {
mHolder.ivPostphoto.setVisibility(View.VISIBLE);
FirebaseStorage fs = FirebaseStorage.getInstance();
fs.getReferenceFromUrl(photourl);
StorageReference mImageRef = fs.getReference();
String ssss = fs.getReferenceFromUrl(photourl).getName();
mImageRef.child("post_photos/" + ssss).getDownloadUrl()
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
mHolder.postImageUri = uri;
/* Picasso.with(holder.ivPostphoto.getContext()).
load(uri).
placeholder(R.drawable.ic_image_black_24dp).
into(holder.ivPostphoto);*/
/* float thumb=0;
Glide.with(context).asBitmap()
.load(uri)
.thumbnail(thumb)
.into(mHolder.ivPostphoto);*/
Picasso.with(context).load(uri).fit().centerCrop()
.placeholder(R.drawable.ic_image_black_24dp)
.error(R.drawable.ic_image_black_24dp)
.into(mHolder.ivPostphoto);
//ivPostphoto.setImageURI(uri);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
final String senderId = list.get(position).getSenderid();
StorageReference mProfileRef =
FirebaseStorage.getInstance().getReference();
mProfileRef.child("profile_pic/" + senderId + ".jpg").getDownloadUrl()
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Picasso.with(context).load(uri).into(holder.ivSenderphoto);
Picasso.with(context).load(uri).fit().centerCrop()
.placeholder(R.drawable.ic_account_circle_black_24dp)
.error(R.drawable.ic_account_circle_black_24dp)
.into(mHolder.ivSenderphoto);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Picasso.with(context).load(R.drawable.ic_account_circle_black_24dp).fit().centerCrop()
.placeholder(R.drawable.ic_account_circle_black_24dp)
.error(R.drawable.ic_account_circle_black_24dp)
.into(mHolder.ivSenderphoto);
}
});
}
@Override
public int getItemCount() {
return list.size();
}
public class NewPostHolder extends RecyclerView.ViewHolder {
TextView tvSendername,tvDatetime,tvServiceType,tvPostText,tvTotalLike,tvTotalComments;
ImageView ivSenderphoto;
PhotoView ivPostphoto;
ImageButton ibLike,ibComments,ibShare, ibCall, ibMap;
LinearLayout llPostAproval;
Button btPostApprove,btPostDelete;
CardView cardHome;
Uri postImageUri;
View rootView;
RelativeLayout rlPosts;
View view;
NewPostHolder(View itemView) {
super(itemView);
view = itemView;
tvSendername=(TextView)itemView.findViewById(R.id.tv_poster_username);
tvDatetime=(TextView)itemView.findViewById(R.id.tv_poster_datetime);
tvServiceType=(TextView)itemView.findViewById(R.id.tv_poster_servicetype);
tvPostText=(TextView)itemView.findViewById(R.id.tv_poster_text);
tvTotalLike=(TextView)itemView.findViewById(R.id.tv_poster_total_likes);
tvTotalComments=(TextView)itemView.findViewById(R.id.tv_poster_total_comments);
ivSenderphoto=(ImageView)itemView.findViewById(R.id.iv_poster_photo);
ivPostphoto=(PhotoView) itemView.findViewById(R.id.iv_poster_images);
ibLike=(ImageButton)itemView.findViewById(R.id.ib_poster_like);
ibComments=(ImageButton)itemView.findViewById(R.id.ib_poster_comments);
ibShare=(ImageButton)itemView.findViewById(R.id.ib_poster_share);
ibCall=(ImageButton)itemView.findViewById(R.id.ib_poster_call);
ibMap=(ImageButton)itemView.findViewById(R.id.ib_poster_map);
llPostAproval=(LinearLayout)itemView.findViewById(R.id.linearPosterApproval);
btPostApprove=(Button)itemView.findViewById(R.id.bt_poster_approve);
btPostDelete=(Button)itemView.findViewById(R.id.bt_poster_delete);
cardHome=(CardView)itemView.findViewById(R.id.card_home_post);
rlPosts=(RelativeLayout)itemView.findViewById(R.id.rl_home_posts);
tvPostText.setTextIsSelectable(true);
}
}
}
现在,我的问题和我在前三个 id 之后很难获取文档 ID(三个 id 是我的限制),在获取前三个文档后,错误显示如下。请帮助我获取下一个查询
文档ID。希望你能理解。谢谢你的帮助错误:
2020-02-15 16:56:56.138 22675-22675/app.burhani.dholkaapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.burhani.dholkaapp, PID: 22675
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
at java.util.ArrayList.get(ArrayList.java:437)
at app.burhani.dholkaapp.newadapter.NewPostAdapter.onBindViewHolder(NewPostAdapter.java:81)
at app.burhani.dholkaapp.newadapter.NewPostAdapter.onBindViewHolder(NewPostAdapter.java:47)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7056)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7098)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6010)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6277)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6116)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6112)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1391)
at androidx.recyclerview.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1128)
at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1841)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5300)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1163)
at android.view.Choreographer.doCallbacks(Choreographer.java:986)
at android.view.Choreographer.doFrame(Choreographer.java:894)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1148)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
最佳答案
可能是因为您正在发送位置,而您给了您错误,请尝试发送 final String postid=task.getResult().getDocuments().get(position-1).getId() ;
看看您是否得到了您想要的对象。让我知道它适合您
关于android - 如何获取文档 ID? Firestore 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60247307/
我需要您在以下方面提供帮助。近一个月来,我一直在阅读有关任务和异步的内容。 我想尝试在一个简单的 wep api 项目中实现我新获得的知识。我有以下方法,并且它们都按预期工作: public Htt
我的可执行 jar 中有一个模板文件 (.xls)。不需要在运行时我需要为这个文件创建 100 多个副本(稍后将唯一地附加)。用于获取 jar 文件中的资源 (template.xls)。我正在使用
我在查看网站的模型代码时对原型(prototype)有疑问。我知道这对 Javascript 中的继承很有用。 在这个例子中... define([], function () { "use
影响我性能的前三项操作是: 获取滚动条 获取偏移高度 Ext.getStyle 为了解释我的应用程序中发生了什么:我有一个网格,其中有一列在每个单元格中呈现网格。当我几乎对网格的内容做任何事情时,它运
我正在使用以下函数来获取 URL 参数。 function gup(name, url) { name = name.replace(/[\[]/, '\\\[').replace(/[\]]/,
我最近一直在使用 sysctl 来做很多事情,现在我使用 HW_MACHINE_ARCH 变量。我正在使用以下代码。请注意,当我尝试获取其他变量 HW_MACHINE 时,此代码可以完美运行。我还认为
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 要求提供代码的问题必须表现出对所解决问题的最低限度的理解。包括尝试过的解决方案、为什么
由于使用 main-bower-files 作为使用 Gulp 的编译任务的一部分,我无法使用 node_modules 中的 webpack 来require 模块code> dir 因为我会弄乱当
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我使用 Gridlayout 在一行中放置 4 个元素。首先,我有一个 JPanel,一切正常。对于行数变大并且我必须能够向下滚动的情况,我对其进行了一些更改。现在我的 JPanel 上添加了一个 J
由于以下原因,我想将 VolumeId 的值保存在变量中: #!/usr/bin/env python import boto3 import json import argparse import
我正在将 MSAL 版本 1.x 更新为 MSAL-browser 的 Angular 。所以我正在尝试从版本 1.x 迁移到 2.X.I 能够成功替换代码并且工作正常。但是我遇到了 acquireT
我知道有很多关于此的问题,例如 Getting daily averages with pandas和 How get monthly mean in pandas using groupby但我遇到
This is the query string that I am receiving in URL. Output url: /demo/analysis/test?startDate=Sat+
我正在尝试使用 javascript 中的以下代码访问 Geoserver 层 var gkvrtWmsSource =new ol.source.ImageWMS({ u
API 需要一个包含授权代码的 header 。这就是我到目前为止所拥有的: var fullUrl = 'https://api.ecobee.com/1/thermostat?json=\{"s
如何获取文件中的最后一个字符,如果是某个字符,则删除它而不将整个文件加载到内存中? 这就是我目前所拥有的。 using (var fileStream = new FileStream("file.t
我是这个社区的新手,想出了我的第一个问题。 我正在使用 JSP,我成功地创建了 JSP-Sites,它正在使用jsp:setParameter 和 jsp:getParameter 具有单个字符串。
在回答 StoreStore reordering happens when compiling C++ for x86 @Peter Cordes 写过 For Acquire/Release se
我有一个函数,我们将其命名为 X1,它返回变量 Y。该函数在操作 .on("focusout", X1) 中使用。如何获取变量Y?执行.on后X1的结果? 最佳答案 您可以更改 Y 的范围以使其位于函
我是一名优秀的程序员,十分优秀!