0

I am using Recycler View and it is showing error: Type parameter T has incompatible upper bound: View and RecyclerView.

Following is the code:

public class RecyclerView extends AppCompatActivity {
ArrayList<Contact> list=new ArrayList<Contact>();
RecyclerView recyclerView;
android.support.v7.widget.RecyclerView.Adapter adapter;
android.support.v7.widget.RecyclerView.LayoutManager layoutManager;
int[] image_id = {R.drawable.asd, R.drawable.download};
String[] name, email, mobile;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    name = getResources().getStringArray(R.array.person_name);
    email = getResources().getStringArray(R.array.person_email);
    mobile = getResources().getStringArray(R.array.person_mobile);
    int count=0;
    for (String name: name)

       {
           Contact contact =new Contact(image_id[count],name,email[count],mobile[count]);
           count++;
           list.add(contact);
       }

    recyclerView = findViewById(R.id.rv_view);
}
}

XML FILE:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RecyclerView">

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rv_view">
</android.support.v7.widget.RecyclerView>

</RelativeLayout>

I am not using Data Binding.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0

I think you should try refactoring your activity name to something else from RecyclerView.

public class RecyclerView extends AppCompatActivity --> This line should be refactored to RecyclerViewActivity

or you can try replacing line

RecyclerView recyclerView;

with android.support.v7.widget.RecyclerView recyclerView;

anchit
  • 9
  • 1
  • 1
  • 5
0

I think you need to write your own child class to extend "RecyclerView" and other relative classes.

These might be somes examples, such as Simple Android RecyclerView example , or https://www.journaldev.com/10024/android-recyclerview-android-cardview-example-tutorial

Somin Lee
  • 16
  • 2