Android:Activity to Fragment -
i want convert activity fragment able use in navigation drawer have errors
that's activity
public class recyclerviewactivity extends activity { private list<person> persons; private recyclerview rv; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.recyclerview_activity); rv=(recyclerview)findviewbyid(r.id.rv); rv.sethasfixedsize(true); linearlayoutmanager llm = new linearlayoutmanager(this); rv.setlayoutmanager(llm); initializedata(); initializeadapter(); } private void initializedata(){ persons = new arraylist<>(); persons.add(new person("emma wilson", "23 years old", r.drawable.emma)); persons.add(new person("lavery maiss", "25 years old", r.drawable.lavery)); persons.add(new person("lillie watts", "35 years old", r.drawable.lillie)); persons.add(new person("ass","ass",r.drawable.lillie)); persons.add(new person("sfs","sfs",r.drawable.lavery)); persons.add(new person("fdfd" , "sfdfe" ,r.drawable.emma)); } private void initializeadapter(){ rvadapter adapter = new rvadapter(persons); rv.setadapter(adapter); }
}
that's fragment after converted
public class recyclerviewactivity extends fragment { private list<person> persons; private recyclerview rv; public static final string tag = "rec"; @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.recyclerview_activity, container, false); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); rv = (recyclerview) getactivity().findviewbyid(r.id.rv); rv.sethasfixedsize(true); linearlayoutmanager llm = new linearlayoutmanager(this); rv.setlayoutmanager(llm); initializedata(); initializeadapter();} private void initializedata() { persons = new arraylist<>(); persons.add(new person("emma wilson", "23 years old", r.drawable.emma)); persons.add(new person("lavery maiss", "25 years old", r.drawable.lavery)); persons.add(new person("lillie watts", "35 years old", r.drawable.lillie)); persons.add(new person("ass", "ass", r.drawable.lillie)); persons.add(new person("sfs", "sfs", r.drawable.lavery)); persons.add(new person("fdfd", "sfdfe", r.drawable.emma)); } private void initializeadapter() { rvadapter adapter = new rvadapter(persons); rv.setadapter(adapter); }
}
i have error in (this) in linear layout manger initialization
replace this
getactivity()
.
Comments
Post a Comment