android.support.v7.widget.RecyclerView null ? with LinearLayoutManager -
i'm trying view recycled objects add, have problems not understand.
searched internet, , due not set "linearlayoutmanager"
i not know error :
error :
07-23 06:35:00.321 24842-24842/xxx.xxx.xxx.xxxe/androidruntime﹕ fatal exception: main java.lang.nullpointerexception @ android.support.v7.widget.recyclerview.onmeasure(recyclerview.java:1694)
code , fragment2 extends fragment {}
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment init(inflater.inflate(r.layout.fragment_fragment2, container, false)); return inflater.inflate(r.layout.fragment_fragment2, container, false); } public void init(view v){ arraylist<pusheen> pusheens = new arraylist<>(); pusheen pusheen = new pusheen(); pusheen.setid(1); pusheen.setname("pusheen"); pusheen.setpastime("blogger"); pusheens.add(pusheen); pusheen pusheen2 = new pusheen(); pusheen2.setid(2); pusheen2.setname("pusheen"); pusheen2.setpastime("sculpor"); pusheens.add(pusheen2); pusheen pusheen3 = new pusheen(); pusheen3.setid(3); pusheen3.setname("stormy"); pusheen3.setpastime("mage"); pusheens.add(pusheen3); pusheen pusheen4 = new pusheen(); pusheen4.setid(4); pusheen4.setname("pusheen"); pusheen4.setpastime("tribute"); pusheens.add(pusheen4); pusheen pusheen5 = new pusheen(); pusheen5.setid(5); pusheen5.setname("stormy"); pusheen5.setpastime("adventurer"); pusheens.add(pusheen5); //fin de nuestro dataset //configuración del recyclerview, con nuestro dataset y nuestro adapter //aqui buscamos el widget recyclerview recyclerview recyclerview = (recyclerview) v.findviewbyid(r.id.my_recycler_view); //a pesar del tamaño de la pantalla, asegurar que los elementos se vean siempre igual. recyclerview.sethasfixedsize(true); //configuramos la animación por defecto recyclerview.setitemanimator(new defaultitemanimator()); //ahora le pasamos nuestro dataset y la forma en que se vera cada fila. recyclerview.setadapter(new pusheenadapter(pusheens, r.layout.row_notifications)); //importante, ahora podemos indicar si mostrar los elementos como fila o como grilla, en este //caso setlayoutmanager() esta configurado como grilla de una columna, es por es eso que se ve //como fila, recordar que el mismo resultado se obtiene con // recyclerview.setlayoutmanager(new linearlayoutmanager(this)); final linearlayoutmanager layoutmanager = new linearlayoutmanager(getactivity()); layoutmanager.setorientation(linearlayoutmanager.vertical); layoutmanager.scrolltoposition(0); recyclerview.setlayoutmanager(layoutmanager); }
call recyclerview.setlayoutmanager(layoutmanager);
before setadapter
Comments
Post a Comment