android - error RecyclerView: No adapter attached; skipping layout when running program -
i have tried answer @ stackoverflow relate problem. wanna show data firebase in imageview , textview. there's error recyclerview: no adapter attached; skipping layout. coding :
menumanajemenkendaraanfragment.java
public class menumanajemenkendaraanfragment extends fragment { private recyclerview recyclerview; private menumanajemenkendaraanadapter adapter; private databasereference mdatabase; //private progressdialog progressdialog; private list<datakendaraan> datakendaraan; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { getactivity().settitle("manajemen kendaraan"); view v = inflater.inflate(r.layout.fragment_menu_manajemen_kendaraan, container, false); floatingactionbutton fab_tambah_kendaraan = (floatingactionbutton) v.findviewbyid(r.id.fab); mdatabase = firebasedatabase.getinstance().getreference(); recyclerview = (recyclerview) v.findviewbyid(r.id.listviewkendaraan); recyclerview.sethasfixedsize(true); final fragmentactivity c = getactivity(); linearlayoutmanager layoutmanager = new linearlayoutmanager(c); recyclerview.setlayoutmanager(layoutmanager); datakendaraan = new arraylist<>(); mdatabase = firebasedatabase.getinstance().getreference(constants.database_path_uploads); mdatabase.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { //dismissing progress dialog //iterating through values in database (datasnapshot postsnapshot : datasnapshot.getchildren()) { datakendaraan upload = postsnapshot.getvalue(datakendaraan.class); datakendaraan.add(upload); } adapter = new menumanajemenkendaraanadapter(getactivity(), datakendaraan); //adding adapter recyclerview recyclerview.setadapter(adapter); }
fragment_menu_manajemen_kendaraan.xml
<framelayout 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"> <android.support.v7.widget.recyclerview android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:cliptopadding="false" android:padding="5dp" android:scrollbars="vertical" android:id="@+id/listviewkendaraan"> </android.support.v7.widget.recyclerview> <android.support.design.widget.floatingactionbutton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:clickable="true" app:fabsize="normal" android:src="@drawable/ic_add_fab" android:layout_gravity="end|bottom"/> </framelayout>
menumanajemenkendraanadapter.java
public class menumanajemenkendaraanadapter extends recyclerview.adapter<menumanajemenkendaraanadapter.viewholder> { private context context; private list<datakendaraan> datakendaraan; public menumanajemenkendaraanadapter(context context, list<datakendaraan> datakendaraan) { this.datakendaraan = datakendaraan; this.context = context; } @override public viewholder oncreateviewholder(viewgroup parent, int viewtype) { view v = layoutinflater.from(parent.getcontext()) .inflate(r.layout.adapter_menu_manajemen_kendaraan, parent, false); viewholder viewholder = new viewholder(v); return viewholder; } @override public void onbindviewholder(viewholder holder, int position) { datakendaraan data = datakendaraan.get(position); holder.tipekendaraan.settext(data.gettipekendaraan()); glide.with(context).load(data.geturifotokendaraan()).into(holder.fotokendaraan); } @override public int getitemcount() { return datakendaraan.size(); } class viewholder extends recyclerview.viewholder { public textview tipekendaraan; public imageview fotokendaraan; public viewholder(view itemview) { super(itemview); tipekendaraan = (textview)itemview.findviewbyid(r.id.tipe_kendaraan); } }
adapter_menu_manajemen_kendaraan.xml
<android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="90dp" android:layout_margin="5dp"> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_frame" android:layout_width="match_parent" android:layout_height="match_parent"> </framelayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp"> <imageview android:id="@+id/imageviewfotokendaraan" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:layout_marginright="10dp"/> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="5"> <textview android:text="tipe kendaraan" android:layout_width="match_parent" android:layout_height="wrap_content" android:fontfamily="sans-serif-black" android:textcolor="@color/coloraccent" android:paddingbottom="2dp" android:id="@+id/tipe_kendaraan" android:textsize="16sp"/> </linearlayout> </linearlayout>
thank help.
view v = layoutinflater.from(context) .inflate(r.layout.adapter_menu_manajemen_kendaraan, parent, false); viewholder viewholder = new viewholder(v); return viewholder;
Comments
Post a Comment