I'm trying to setup a RecyclerView in my Android Project but i cannot refer to my list because using the code "recyclerView = view.findViewById(R.id.list)" give me the error Cannot resolve symbol "list". If I try to type "R.id." i cannot find R.id.list but I'm sure that I give it the id "list".
I just added dependencies and the import statement in my code. I tried to resync and clean project but with no result.
here my dependencies (build.gradle (app)):
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
here my import:
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
here the wrong code:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
recyclerView = view.findViewById(R.id.list);
}
here the declaration of the RecyclerView in the xml file:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
Thank you in advance!
Try File > Invalidate Caches / Restart
Also, shift this code to onCreateView()
recyclerView = view.findViewById(R.id.list);
Where view should be the view you get after inflating.
关闭项目,然后尝试使用rm -r /pathToYourProject/.gradle删除.gradle和.idea,然后打开项目并进行同步
Try in your activity:
import your.project.name.R;
Hope it helps.
you forget somthing
just set this line before recyclerView = view.findViewById(R.id.list);
setContentview(R.layout.THE_LAYOUT_THAT_CONTAIN_YOUR_RECYCLERVIEW);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.