无法解析符号ID [英] Cannot resolve Symbol id
问题描述
我有一个recylcerView称为"Notes",我试图添加一个新的称为"Assignments"的recylerview,这将在notes recylerview项内创建. 当我单击recylerview项(注释)时,它将把我发送到ClassworkActivity,其中作业的recyclerview将被添加到其中. 因此,我想将作业recyclerview添加为notes recyclerview的子代.
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.
这就是我尝试过的:
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));
}
});
但我在此行遇到错误:
databaseReference = firebaseDatabase.getReference().
child("Users").
child(userID).
child("Notes").
child(id).
child("Assignments");
因为我没有创建变量id:child(id).
,它是注释列表的ID
谁能告诉我如何声明此变量?
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 ?
另一件事是,分配是在NotesActivity中而不是在ClassworkActivity中创建为Notes的!
Another thing is that the assignments are created as a Notes in the NotesActivity, not in the ClassworkActivity !
另外,这是我项目的github链接,请看一下: Notes应用
Also, this is a github link of my project, Please take a look at it : Notes App
请帮助!
推荐答案
当您单击Notes的recyclerView项时,获得noteID
用来单击位置的信息.
When you click on recyclerView item of Notes, get the noteID
usinng which position is clicked.
现在,当您打开ClassworkActivity
时,请使用意图将其绑定,并在ClassworkActivity
onCreate()中获取它,并在创建AssignmentAdapter
时使用该noteID作为ID.
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.
通过intent传递noteId:
pass noteId using intent as:
Intent myIntent = new Intent(CurrentActivity.this, ClassworkActivity.class); // UPDATE CURRENT ACTIVITY NAME
myIntent.putExtra("noteID", noteID);
startActivity(myIntent);
并在ClassworkActivity
onCreate()中以以下方式接收:
and receive in ClassworkActivity
onCreate() as:
Intent mIntent = getIntent();
int id = mIntent.getIntExtra("noteID", 0);
这篇关于无法解析符号ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!