Cannot resolve Symbol id

蹲街弑〆低调 提交于 2020-06-17 09:10:30

问题


I have a recylcerView calles "Notes", I'm trying to add an new recylerview called "Assignments" wich will be created inside the notes recylerview item. When I click on a recylerview item (notes) it send me to ClassworkActivity in wich the assignments' recyclerview will be added to it. So I want to add the assignment recyclerview as a child of the notes recyclerview.

Here's what I tried :

final AssignmentAdapter assignmentAdapter=new AssignmentAdapter(assignlist,this);
recyclerView.setAdapter(assignmentAdapter);

FloatingActionButton fab = findViewById(R.id.fab);


mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();


String userID = mCurrentUser.getUid();


firebaseDatabase=FirebaseDatabase.getInstance();

databaseReference = firebaseDatabase.getReference().child("Users").child(userID).child("Notes").child(id).child("Assignments");
databaseReference.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

        for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
        {
            AssignListdata listdata=dataSnapshot1.getValue(AssignListdata.class);
            assignlist.add(listdata);

        }
        assignmentAdapter.notifyDataSetChanged();

    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
});

// fab
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        startActivity(new Intent(getApplicationContext(), AddAssignmentActivity.class));
    }
});

But I'm getting the error on this line :

databaseReference = firebaseDatabase.getReference().
child("Users").
child(userID).
child("Notes").
child(id).
child("Assignments");

since I didn't create the variable id : child(id). which is the id of the Notes List Can anyone tell me how to declare this variable ?

Another thing is that the assignments are created as a Notes in the NotesActivity, not in the ClassworkActivity !

Also, this is a github link of my project, Please take a look at it : Notes App

Please help!


回答1:


When you click on recyclerView item of Notes, get the noteID usinng which position is clicked.

now when you open ClassworkActivity, bind that id with intent and get it in ClassworkActivity onCreate() and while creating AssignmentAdapter use that noteID as id.

pass noteId using intent as:

Intent myIntent = new Intent(CurrentActivity.this, ClassworkActivity.class); // UPDATE CURRENT ACTIVITY NAME
myIntent.putExtra("noteID", noteID);
startActivity(myIntent);

and receive in ClassworkActivity onCreate() as:

Intent mIntent = getIntent();
int id = mIntent.getIntExtra("noteID", 0);


来源:https://stackoverflow.com/questions/61064042/cannot-resolve-symbol-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!