1
I have a recyclerview that pulls data from firebase, but it takes all the data at once, and this causes the application to lock, as I do for it to show only the first 10 and as the user goes down scrool it goes downloading more data?
Adapter
public VideoListAdapter(@NonNull Activity context, @LayoutRes
int resource, @NonNull List<VideoUpload> objects) {
super(context, R.layout.image_item, objects);
this.context = context;
listImage = objects;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
autenticacao = FirebaseAuth.getInstance();
@SuppressLint("ViewHolder") View v = inflater.inflate(R.layout.image_item, parent, false);
imgList = new ArrayList<>();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("Videos/");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Fetch image data from firebase database
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
VideoUpload video = snapshot.getValue(VideoUpload.class);
string = video.getUrl();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
telefone = v.findViewById(R.id.contatoResponsavel);
posicao = v.findViewById(R.id.posicaoJogador);
idade = v.findViewById(R.id.idadeJogador);
localidade = v.findViewById(R.id.localidadeJogador);
TextView tvName = v.findViewById(R.id.tvImageName);
imgYoutube = v.findViewById(R.id.videoPlayer);
YouTubeThumbnailView youTubePlayerView = (YouTubeThumbnailView) v.findViewById(R.id.youtube_thumbnail);
String tvNameString;
final String linkFormatado;
final String linkYoutube;
linkYoutube = listImage.get(position).getUrl();
linkFormatado = linkYoutube.replace("https://youtu.be/", "");
posicao.setText("Posição: " + listImage.get(position).getPosicao());
idade.setText("Idade: " + listImage.get(position).getIdade());
localidade.setText("Localização: " + listImage.get(position).getEstado());
tvNameString = listImage.get(position).getName();
telefone.setText("Contato: " + listImage.get(position).getTelefone());
tvName.setText("Nome: " + tvNameString);
imgYoutube.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = YouTubeStandalonePlayer.createVideoIntent((Activity) getContext(),
"AIzaSyBvrGBKv7AU19B8DPp9ubiWPRS9FE7Ek9w",
linkFormatado,
100,
true,
false);
getContext().startActivity(intent);
}
});
return v;
}
}
Activity
container = findViewById(R.id.container);
anim = (AnimationDrawable) container.getBackground();
anim.setEnterFadeDuration(2500);
anim.setExitFadeDuration(5000);
anim.start();
imgList = new ArrayList<>();
lv = findViewById(R.id.listViewImage);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation2 = (BottomNavigationView) findViewById(R.id.navigation);
navigation2.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Aguarde ....");
progressDialog.show();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("Videos/");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
progressDialog.dismiss();
//Fetch image data from firebase database
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
//ImageUpload class require default constructor
VideoUpload video = snapshot.getValue(VideoUpload.class);
imgList.add(video);
}
adapter = new VideoListAdapter(HomeJogadorActivity.this, R.layout.image_item, imgList);
//Set adapter for listview
lv.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}
@Override
public void onBackPressed() {
}
}