android - Cardslib's CardRecyclerView is always null -


i developing cardslib library , implementing this example.

although slavishly follow instructions in tutorial when create cardrecyclerview object, object appears null.

check code:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.native_recyclerview_card_layout);      arraylist<card> cards = new arraylist<card>();      //create card     card card = new card(this);//getcontext()      //create cardheader , add header card     cardheader header = new cardheader(this);     card.addcardheader(header);      cards.add(card);      cardarrayrecyclerviewadapter mcardarrayadapter = new cardarrayrecyclerviewadapter(this,cards);     //staggered grid view     cardrecyclerview mrecyclerview = (cardrecyclerview)                     this.findviewbyid(r.id.carddemo_recyclerview); //**mrecyclerview null here**     mrecyclerview.sethasfixedsize(false); //**nullpointerexception here**     mrecyclerview.setlayoutmanager(new linearlayoutmanager(this));      //set empty view     if (mrecyclerview != null) {         mrecyclerview.setadapter(mcardarrayadapter);     }      //set card in cardview     cardviewnative cardview = (cardviewnative) this.findviewbyid(r.id.carddemo);     cardview.setcard(card); } 

cardslib_activity_recycler.xml:

<it.gmariotti.cardslib.library.recyclerview.view.cardrecyclerview    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:card="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    card:list_card_layout_resourceid="@layout/native_recyclerview_card_layout"    android:id="@+id/carddemo_recyclerview"/> 

cardslib_item_card_view:

<?xml version="1.0" encoding="utf-8"?>  <android.support.v7.widget.cardview     xmlns:card_view="http://schemas.android.com/apk/res-auto"     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/card_view"     android:layout_width="match_parent" android:layout_height="match_parent"     card_view:cardcornerradius="4dp"     android:layout_margin="5dp">  <relativelayout android:id="@+id/nativecardlayout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:clickable="true"     android:background="?android:selectableitembackground">            <!--some more layout-->  </relativelayout> </android.support.v7.widget.cardview> 

i don't see why though referencing cardrecyclerview object correct xml cardslib_activity_recycler.xml, find null. did overlook something?

maybe because set setcontentview(r.layout.native_recyclerview_card_layout) cardrecyclerview in cardslib_activity_recycler.xml ?

technically findviewbyid finds view id registered in view hierarchy of layout set setcontentview. if want combine views should use <include>.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -