Я новичок в Android studio. Я использую адаптер восстановления Firestore для отображения списка лиг после того, как пользователь войдет в систему;тем не менее, в обзоре активности Leaguelist не отображается никаких элементов.Он показывает только список лиг, когда я пытаюсь добавить другую лигу, используя плавающую операцию ActionButton (все еще используя то же действие)Затем, если я перейду к следующему занятию, а затем вернусь к занятию лигулистов, я не увижу ни одного из предметов лиги, если не попытаюсь снова добавить еще одну лигу.
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