RecyclerView using FirebaseRecyclerAdapter not displaying data
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm new to Android studio.I'm using firestore recyclerview adapter to display list a of leagues after a user signs in; however, the recyclerview of Leaguelist activity isn't showing any items. It only shows the list of leagues when I try to add another league using floatingActionButton(still using the same activity). Then if I move on to the next activity then go back to the Leaguelist activity, I don't see any of league items unless I try to add another league again.
public class LeagueListActivity extends AppCompatActivity implements LeagueRecycleAdapter.OnItemClickListener{
List<League> leagueList;
LeaguesRepository leaguesRepository = new LeaguesRepository();
ListView listView;
LeagueAdapter adapter;
CheckBox checkBox;
static final int GET_LEAGUE_NAME = 1;
FloatingActionButton btnAddLeague;
private CoordinatorLayout coordinatorLayout;
private RecyclerView recyclerView;
private CollectionReference leagueRef = FirebaseFirestore.getInstance().collection("myLeague");
private LeagueRecycleAdapter leagueRecycleAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_league_recycleview);
coordinatorLayout=findViewById(R.id.coordinator_layout_leagues);
setUpRecycleView();
btnAddLeague =findViewById(R.id.floatingButton_add_league);
btnAddLeague.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
}
});
// hide the title of this activity
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.context_menu, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GET_LEAGUE_NAME) {
if (resultCode == Activity.RESULT_OK) {
if(data.getStringExtra("SAVE").isEmpty()){
Toast.makeText(
this, "You didn't add a league", Toast.LENGTH_SHORT).show();
}else{
leaguesRepository.addLeague(data.getStringExtra("SAVE"));
}
}
if (resultCode == Activity.RESULT_CANCELED) {
//Write your code if there's no result
Toast.makeText(
this, "Cancelled", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add:
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
return true;
]
case R.id.action_logout:
]
return true;
case android.R.id.home:
logoutUser();
default:
return super.onOptionsItemSelected(item);
}
}
private void logoutUser() {
FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(LeagueListActivity.this, LoginActivity.class));
}
private void setUpRecycleView(){
Query query=leagueRef;
FirestoreRecyclerOptions<League> options = new FirestoreRecyclerOptions.Builder<League>()
.setQuery(query,League.class).build();
leagueRecycleAdapter=new LeagueRecycleAdapter(options);
recyclerView=findViewById(R.id.recycler_view_league);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(leagueRecycleAdapter);
leagueRecycleAdapter.setOnItemClickListener(new LeagueRecycleAdapter.OnItemClickListener() {
@Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
String id=documentSnapshot.getId();
League league = new League();
league.setDocumentId(id);
Intent intent = new Intent(LeagueListActivity.this, NamingTeamsActivity.class);
intent.putExtra("leagueId", id);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
leagueRecycleAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
leagueRecycleAdapter.stopListening();
}
}
[LeaguelistActivity][1]
[adding a league][2][recycleview is populated][3]
[1]: https://i.stack.imgur.com/7EQN1.png
[2]: https://i.stack.imgur.com/5egzo.png
[3]: https://i.stack.imgur.com/Ii87c.png

add a comment |
I'm new to Android studio.I'm using firestore recyclerview adapter to display list a of leagues after a user signs in; however, the recyclerview of Leaguelist activity isn't showing any items. It only shows the list of leagues when I try to add another league using floatingActionButton(still using the same activity). Then if I move on to the next activity then go back to the Leaguelist activity, I don't see any of league items unless I try to add another league again.
public class LeagueListActivity extends AppCompatActivity implements LeagueRecycleAdapter.OnItemClickListener{
List<League> leagueList;
LeaguesRepository leaguesRepository = new LeaguesRepository();
ListView listView;
LeagueAdapter adapter;
CheckBox checkBox;
static final int GET_LEAGUE_NAME = 1;
FloatingActionButton btnAddLeague;
private CoordinatorLayout coordinatorLayout;
private RecyclerView recyclerView;
private CollectionReference leagueRef = FirebaseFirestore.getInstance().collection("myLeague");
private LeagueRecycleAdapter leagueRecycleAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_league_recycleview);
coordinatorLayout=findViewById(R.id.coordinator_layout_leagues);
setUpRecycleView();
btnAddLeague =findViewById(R.id.floatingButton_add_league);
btnAddLeague.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
}
});
// hide the title of this activity
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.context_menu, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GET_LEAGUE_NAME) {
if (resultCode == Activity.RESULT_OK) {
if(data.getStringExtra("SAVE").isEmpty()){
Toast.makeText(
this, "You didn't add a league", Toast.LENGTH_SHORT).show();
}else{
leaguesRepository.addLeague(data.getStringExtra("SAVE"));
}
}
if (resultCode == Activity.RESULT_CANCELED) {
//Write your code if there's no result
Toast.makeText(
this, "Cancelled", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add:
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
return true;
]
case R.id.action_logout:
]
return true;
case android.R.id.home:
logoutUser();
default:
return super.onOptionsItemSelected(item);
}
}
private void logoutUser() {
FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(LeagueListActivity.this, LoginActivity.class));
}
private void setUpRecycleView(){
Query query=leagueRef;
FirestoreRecyclerOptions<League> options = new FirestoreRecyclerOptions.Builder<League>()
.setQuery(query,League.class).build();
leagueRecycleAdapter=new LeagueRecycleAdapter(options);
recyclerView=findViewById(R.id.recycler_view_league);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(leagueRecycleAdapter);
leagueRecycleAdapter.setOnItemClickListener(new LeagueRecycleAdapter.OnItemClickListener() {
@Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
String id=documentSnapshot.getId();
League league = new League();
league.setDocumentId(id);
Intent intent = new Intent(LeagueListActivity.this, NamingTeamsActivity.class);
intent.putExtra("leagueId", id);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
leagueRecycleAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
leagueRecycleAdapter.stopListening();
}
}
[LeaguelistActivity][1]
[adding a league][2][recycleview is populated][3]
[1]: https://i.stack.imgur.com/7EQN1.png
[2]: https://i.stack.imgur.com/5egzo.png
[3]: https://i.stack.imgur.com/Ii87c.png

Have you tried to commentrecyclerView.setHasFixedSize(true);
?
– Alex Mamo
Jan 3 at 16:05
Yes, I did. Nothing happened though unless I try to add another league item
– Assi
Jan 4 at 1:35
add a comment |
I'm new to Android studio.I'm using firestore recyclerview adapter to display list a of leagues after a user signs in; however, the recyclerview of Leaguelist activity isn't showing any items. It only shows the list of leagues when I try to add another league using floatingActionButton(still using the same activity). Then if I move on to the next activity then go back to the Leaguelist activity, I don't see any of league items unless I try to add another league again.
public class LeagueListActivity extends AppCompatActivity implements LeagueRecycleAdapter.OnItemClickListener{
List<League> leagueList;
LeaguesRepository leaguesRepository = new LeaguesRepository();
ListView listView;
LeagueAdapter adapter;
CheckBox checkBox;
static final int GET_LEAGUE_NAME = 1;
FloatingActionButton btnAddLeague;
private CoordinatorLayout coordinatorLayout;
private RecyclerView recyclerView;
private CollectionReference leagueRef = FirebaseFirestore.getInstance().collection("myLeague");
private LeagueRecycleAdapter leagueRecycleAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_league_recycleview);
coordinatorLayout=findViewById(R.id.coordinator_layout_leagues);
setUpRecycleView();
btnAddLeague =findViewById(R.id.floatingButton_add_league);
btnAddLeague.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
}
});
// hide the title of this activity
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.context_menu, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GET_LEAGUE_NAME) {
if (resultCode == Activity.RESULT_OK) {
if(data.getStringExtra("SAVE").isEmpty()){
Toast.makeText(
this, "You didn't add a league", Toast.LENGTH_SHORT).show();
}else{
leaguesRepository.addLeague(data.getStringExtra("SAVE"));
}
}
if (resultCode == Activity.RESULT_CANCELED) {
//Write your code if there's no result
Toast.makeText(
this, "Cancelled", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add:
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
return true;
]
case R.id.action_logout:
]
return true;
case android.R.id.home:
logoutUser();
default:
return super.onOptionsItemSelected(item);
}
}
private void logoutUser() {
FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(LeagueListActivity.this, LoginActivity.class));
}
private void setUpRecycleView(){
Query query=leagueRef;
FirestoreRecyclerOptions<League> options = new FirestoreRecyclerOptions.Builder<League>()
.setQuery(query,League.class).build();
leagueRecycleAdapter=new LeagueRecycleAdapter(options);
recyclerView=findViewById(R.id.recycler_view_league);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(leagueRecycleAdapter);
leagueRecycleAdapter.setOnItemClickListener(new LeagueRecycleAdapter.OnItemClickListener() {
@Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
String id=documentSnapshot.getId();
League league = new League();
league.setDocumentId(id);
Intent intent = new Intent(LeagueListActivity.this, NamingTeamsActivity.class);
intent.putExtra("leagueId", id);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
leagueRecycleAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
leagueRecycleAdapter.stopListening();
}
}
[LeaguelistActivity][1]
[adding a league][2][recycleview is populated][3]
[1]: https://i.stack.imgur.com/7EQN1.png
[2]: https://i.stack.imgur.com/5egzo.png
[3]: https://i.stack.imgur.com/Ii87c.png

I'm new to Android studio.I'm using firestore recyclerview adapter to display list a of leagues after a user signs in; however, the recyclerview of Leaguelist activity isn't showing any items. It only shows the list of leagues when I try to add another league using floatingActionButton(still using the same activity). Then if I move on to the next activity then go back to the Leaguelist activity, I don't see any of league items unless I try to add another league again.
public class LeagueListActivity extends AppCompatActivity implements LeagueRecycleAdapter.OnItemClickListener{
List<League> leagueList;
LeaguesRepository leaguesRepository = new LeaguesRepository();
ListView listView;
LeagueAdapter adapter;
CheckBox checkBox;
static final int GET_LEAGUE_NAME = 1;
FloatingActionButton btnAddLeague;
private CoordinatorLayout coordinatorLayout;
private RecyclerView recyclerView;
private CollectionReference leagueRef = FirebaseFirestore.getInstance().collection("myLeague");
private LeagueRecycleAdapter leagueRecycleAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_league_recycleview);
coordinatorLayout=findViewById(R.id.coordinator_layout_leagues);
setUpRecycleView();
btnAddLeague =findViewById(R.id.floatingButton_add_league);
btnAddLeague.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
}
});
// hide the title of this activity
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.context_menu, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GET_LEAGUE_NAME) {
if (resultCode == Activity.RESULT_OK) {
if(data.getStringExtra("SAVE").isEmpty()){
Toast.makeText(
this, "You didn't add a league", Toast.LENGTH_SHORT).show();
}else{
leaguesRepository.addLeague(data.getStringExtra("SAVE"));
}
}
if (resultCode == Activity.RESULT_CANCELED) {
//Write your code if there's no result
Toast.makeText(
this, "Cancelled", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add:
startActivityForResult(new Intent
(LeagueListActivity.this,
EditNameActivity.class), GET_LEAGUE_NAME);
return true;
]
case R.id.action_logout:
]
return true;
case android.R.id.home:
logoutUser();
default:
return super.onOptionsItemSelected(item);
}
}
private void logoutUser() {
FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(LeagueListActivity.this, LoginActivity.class));
}
private void setUpRecycleView(){
Query query=leagueRef;
FirestoreRecyclerOptions<League> options = new FirestoreRecyclerOptions.Builder<League>()
.setQuery(query,League.class).build();
leagueRecycleAdapter=new LeagueRecycleAdapter(options);
recyclerView=findViewById(R.id.recycler_view_league);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(leagueRecycleAdapter);
leagueRecycleAdapter.setOnItemClickListener(new LeagueRecycleAdapter.OnItemClickListener() {
@Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
String id=documentSnapshot.getId();
League league = new League();
league.setDocumentId(id);
Intent intent = new Intent(LeagueListActivity.this, NamingTeamsActivity.class);
intent.putExtra("leagueId", id);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
leagueRecycleAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
leagueRecycleAdapter.stopListening();
}
}
[LeaguelistActivity][1]
[adding a league][2][recycleview is populated][3]
[1]: https://i.stack.imgur.com/7EQN1.png
[2]: https://i.stack.imgur.com/5egzo.png
[3]: https://i.stack.imgur.com/Ii87c.png


edited Jan 3 at 3:36
Frank van Puffelen
245k30389417
245k30389417
asked Jan 3 at 3:24
AssiAssi
1
1
Have you tried to commentrecyclerView.setHasFixedSize(true);
?
– Alex Mamo
Jan 3 at 16:05
Yes, I did. Nothing happened though unless I try to add another league item
– Assi
Jan 4 at 1:35
add a comment |
Have you tried to commentrecyclerView.setHasFixedSize(true);
?
– Alex Mamo
Jan 3 at 16:05
Yes, I did. Nothing happened though unless I try to add another league item
– Assi
Jan 4 at 1:35
Have you tried to comment
recyclerView.setHasFixedSize(true);
?– Alex Mamo
Jan 3 at 16:05
Have you tried to comment
recyclerView.setHasFixedSize(true);
?– Alex Mamo
Jan 3 at 16:05
Yes, I did. Nothing happened though unless I try to add another league item
– Assi
Jan 4 at 1:35
Yes, I did. Nothing happened though unless I try to add another league item
– Assi
Jan 4 at 1:35
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015928%2frecyclerview-using-firebaserecycleradapter-not-displaying-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015928%2frecyclerview-using-firebaserecycleradapter-not-displaying-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried to comment
recyclerView.setHasFixedSize(true);
?– Alex Mamo
Jan 3 at 16:05
Yes, I did. Nothing happened though unless I try to add another league item
– Assi
Jan 4 at 1:35