android - Can't make Fragment with RecyclerView work -


i have create list inside 1 of fragments cannot make recyclerview work, searching internet whole day followed tutorials not figure out why not working

row_item.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.recyclerview 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:id="@+id/list"     android:name="com.streak.roadpoliceviolations.violationfragment"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_marginleft="16dp"     android:layout_marginright="16dp"     app:layoutmanager="linearlayoutmanager"     tools:context="com.streak.roadpoliceviolations.violationfragment"     tools:listitem="@layout/fragment_violation" /> 

adapter:

public class violationadapter extends recyclerview.adapter<violationadapter.myviewholder>{      private layoutinflater inflater;     list<violationitem> data= collections.emptylist();      public violationadapter(list<violationitem> data) {         //inflater = layoutinflater.from(context);         this.data = data;     }      @override     public myviewholder oncreateviewholder(viewgroup parent, int viewtype) {         view view = inflater.inflate(r.layout.fragment_violation, parent, false);         myviewholder holder = new myviewholder(view);         return holder;     }      @override     public void onbindviewholder(myviewholder holder, int position) {         violationitem current = data.get(position);         holder.txt1.settext(current.txt1);         holder.txt2.settext(current.txt2);     }      @override     public int getitemcount() {         return 0;     }      class myviewholder extends recyclerview.viewholder {         textview txt1;         textview txt2;          public myviewholder(view itemview) {             super(itemview);             txt1= (textview) itemview.findviewbyid(r.id.txt1);             txt2= (textview) itemview.findviewbyid(r.id.txt2);         }     } } 

fragment class

public class violationfragment extends fragment {      private violationadapter adapter;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          view view = inflater.inflate(r.layout.fragment_violation_list, container, false);         recyclerview rv = (recyclerview) view.findviewbyid(r.id.list);         adapter = new violationadapter(getactivity(),getdata());         rv.setadapter(adapter);         rv.setlayoutmanager(new linearlayoutmanager(getactivity()));         return view;     }      public static list<violationitem> getdata() {         list<violationitem> data = new arraylist<>();         string[] txts1 = {"aaa","bbb","ccc"};         string[] txts2 = {"111","222","333"};         for(int i=0; i<=txts1.length; i++) {             violationitem c = new violationitem();             c.txt1=txts1[i];             c.txt2=txts2[i];             data.add(c);         }         return data;     }      private list<violationitem> createlist() {         list<violationitem> data = new arraylist<>();         return data;     } } 

everything passes without single warning cannot place fragment container

in mine activity i'm calling fragment following code

//initial fragment violationfragment frag = new violationfragment(); fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.frame_container, frag).commit(); 

getting error during build

error:(77, 75) error: incompatible types: violationfragment cannot converted fragment 

and if change frag initialization fragment frag = new violationfragment(); same error.

how fix , make fragment work?!

as remember must use support library fragment make work. please check , confirm.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -