android - How do I work with fragments with FirebaseRecyclerAdapter? -
when load fragment activity. app crashes. how called fragment :
recieverfragment recieverfragment = new recieverfragment(); fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction().replace(r.id.recieverrelative,recieverfragment).commit(); toast.maketext(this,"reciever",toast.length_short).show();
it crashes app still shows toast. can me on please? working on hours , hours. cannot find did wrong.
here fragment :
import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; import android.widget.toast; import com.firebase.ui.database.firebaserecycleradapter; import com.google.firebase.database.databasereference; import com.google.firebase.database.firebasedatabase; public class recieverfragment extends fragment { public recieverfragment() { // required empty public constructor } private recyclerview mbloglist; private databasereference mdatabasereference; private view v; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { v=inflater.inflate(r.layout.fragment_reciever, container, false); mbloglist= (recyclerview) v.findviewbyid(r.id.recyclerviewblog_list); mbloglist.sethasfixedsize(true); mdatabasereference = firebasedatabase.getinstance().getreference().child("blog"); firebaserecycleradapter<blog,blogviewholder> mfirebaserecycleradapter=new firebaserecycleradapter<blog, blogviewholder>(blog.class, r.layout.blog_item, blogviewholder.class, mdatabasereference) { @override protected void populateviewholder(blogviewholder viewholder, blog model, int position) { toast.maketext(getcontext(),"reciever",toast.length_short).show(); viewholder.setdate(model.getdate()); viewholder.setdescription(model.getdescription()); viewholder.setfrom(model.getfrom()); viewholder.setto(model.getto()); } }; mbloglist.setlayoutmanager(new linearlayoutmanager(getcontext())); mbloglist.setadapter(mfirebaserecycleradapter); return v; } public static class blogviewholder extends recyclerview.viewholder{ view mview; public blogviewholder(view itemview) { super(itemview); mview=itemview;} public void setdate(string date){ textview date = (textview) mview.findviewbyid(r.id.date); date.settext(date); } public void setdescription(string description){ textview desc= (textview) mview.findviewbyid(r.id.description); desc.settext(description); } public void setfrom(string from){ textview = (textview) mview.findviewbyid(r.id.from); from.settext(from); } public void setto(string to){ textview = (textview) mview.findviewbyid(r.id.to); to.settext(to); } } }
and here fragment layout file :
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.nego.lakshan.nego.recieverfragment" android:id="@+id/place_holder"> <!-- todo: update blank fragment layout --> <android.support.v7.widget.recyclerview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/recyclerviewblog_list"> </android.support.v7.widget.recyclerview>
and using cardview app :
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <linearlayout android:layout_width="match_parent" android:layout_height="104dp" android:orientation="horizontal" android:weightsum="1"> <imageview android:id="@+id/profilepic" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1.05" /> <linearlayout android:layout_width="244dp" android:layout_height="wrap_content" android:orientation="vertical"> <textview android:id="@+id/name" android:layout_width="match_parent" android:layout_height="53dp" /> <textview android:id="@+id/date" android:layout_width="match_parent" android:layout_height="52dp" /> </linearlayout> </linearlayout> <textview android:id="@+id/description" android:layout_width="match_parent" android:layout_height="164dp" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightsum="1"> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="0.16" android:weightsum="1"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="from" android:layout_weight="0.31" /> <textview android:layout_width="match_parent" android:layout_height="0dp" android:text="to" android:layout_weight="0.51" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="0.88" android:weightsum="1"> <textview android:id="@+id/from" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.41" /> <textview android:id="@+id/to" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.19" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> <button android:layout_width="109dp" android:layout_height="wrap_content" android:text="fromlocation"/> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="tolocation"/> </linearlayout> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <button android:layout_width="164dp" android:layout_height="wrap_content" android:text="direction"/> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="message"/> </linearlayout> </linearlayout> </android.support.v7.widget.cardview>
this blog class retrieving data :
public class blog { private string from; private string to; private string description; private string image; private string date; private double tolat; private double tolng; private double fromlat; private double fromlng; public blog(){ } public blog(string from, string to, string description, string image, string date, double tolat, double tolng, double fromlat, double fromlng) { this.from = from; this.to = to; this.description = description; this.image = image; this.date = date; this.tolat = tolat; this.tolng = tolng; this.fromlat = fromlat; this.fromlng = fromlng; } public string getfrom() { return from; } public void setfrom(string from) { this.from = from; } public string getto() { return to; } public void setto(string to) { this.to = to; } public string getimage() { return image; } public void setimage(string image) { this.image = image; } public string getdate() { return date; } public void setdate(string date) { this.date = date; } public double gettolat() { return tolat; } public void settolat(double tolat) { this.tolat = tolat; } public double gettolng() { return tolng; } public void settolng(double tolng) { this.tolng = tolng; } public double getfromlat() { return fromlat; } public void setfromlat(double fromlat) { this.fromlat = fromlat; } public double getfromlng() { return fromlng; } public void setfromlng(double fromlng) { this.fromlng = fromlng; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } }
i have added dependencies. can me please?
Comments
Post a Comment