android - How to reference the inflated view elements? -


i need on this. i'm inflating view. view card view spinner in it.

the view inflated on button click this:

itinerarydetailll = (linearlayout) findviewbyid(r.id.itinerarydetaillinearlayout); view childview = getlayoutinflater().inflate(r.layout.cardview, null); itinerarydetailll.addview(childview); 

now problem whenever click spinner in first inflated card view works fine on clicking on spinner in second inflated view gives me following error:

09-11 10:54:44.976 31698-31698/com.application.marketvisit e/inputeventreceiver: exception dispatching input event. 09-11 10:54:44.976 31698-31698/com.application.marketvisit e/messagequeue-jni: exception in messagequeue callback: handlereceivecallback 09-11 10:54:44.986 31698-31698/com.application.marketvisit e/messagequeue-jni: java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.filter.filter(java.lang.charsequence, android.widget.filter$filterlistener)' on null object reference                                                                                    @ android.widget.autocompletetextview.performfiltering(autocompletetextview.java:861)                                                                                    @ com.weiwangcn.betterspinner.library.material.materialbetterspinner.onfocuschanged(materialbetterspinner.java:49)                                                                                    @ android.view.view.handlefocusgaininternal(view.java:4962)                                                                                    @ android.view.view.requestfocusnosearch(view.java:7678)                                                                                    @ android.view.view.requestfocus(view.java:7657)                                                                                    @ android.view.view.requestfocus(view.java:7624)                                                                                    @ android.view.view.requestfocus(view.java:7603)                                                                                    @ com.weiwangcn.betterspinner.library.material.materialbetterspinner.ontouchevent(materialbetterspinner.java:74)                                                                                    @ android.view.view.dispatchtouchevent(view.java:8471)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                    @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                    @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:2369)                                                                                    @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1719)                                                                                    @ android.app.activity.dispatchtouchevent(activity.java:2742)                                                                                    @ android.support.v7.view.windowcallbackwrapper.dispatchtouchevent(windowcallbackwrapper.java:69)                                                                                    @ android.support.v7.view.windowcallbackwrapper.dispatchtouchevent(windowcallbackwrapper.java:69)                                                                                    @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:2330)                                                                                    @ android.view.view.dispatchpointerevent(view.java:8666)                                                                                    @ android.view.viewrootimpl$viewpostimeinputstage.processpointerevent(viewrootimpl.java:4123)                                                                                    @ android.view.viewrootimpl$viewpostimeinputstage.onprocess(viewrootimpl.java:3989)                                                                                    @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3544)                                                                                    @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3597)                                                                                    @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3563)                                                                                    @ android.view.viewrootimpl$asyncinputstage.forward(viewrootimpl.java:3680)                                                                                    @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3571)                                                                                    @ android.view.viewrootimpl$asyncinputstage.apply(viewrootimpl.java:3737)                                                                                    @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3544)                                                                                    @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3597)                                                                                 @ android.view.viewrootimpl$inputstage.forward(viewrootimpl. 09-11 10:54:44.988 31698-31698/com.application.marketvisit e/androidruntime: fatal exception: main                                                                              process: com.application.marketvisit, pid: 31698                                                                              java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.filter.filter(java.lang.charsequence, android.widget.filter$filterlistener)' on null object reference                                                                                  @ android.widget.autocompletetextview.performfiltering(autocompletetextview.java:861)                                                                                  @ com.weiwangcn.betterspinner.library.material.materialbetterspinner.onfocuschanged(materialbetterspinner.java:49)                                                                                  @ android.view.view.handlefocusgaininternal(view.java:4962)                                                                                  @ android.view.view.requestfocusnosearch(view.java:7678)                                                                                  @ android.view.view.requestfocus(view.java:7657)                                                                                  @ android.view.view.requestfocus(view.java:7624)                                                                                  @ android.view.view.requestfocus(view.java:7603)                                                                                  @ com.weiwangcn.betterspinner.library.material.materialbetterspinner.ontouchevent(materialbetterspinner.java:74)                                                                                  @ android.view.view.dispatchtouchevent(view.java:8471)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2405)                                                                                  @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2106)                                                                                  @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:2369)                                                                                  @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1719)                                                                                  @ android.app.activity.dispatchtouchevent(activity.java:2742)                                                                                  @ android.support.v7.view.windowcallbackwrapper.dispatchtouchevent(windowcallbackwrapper.java:69)                                                                                  @ android.support.v7.view.windowcallbackwrapper.dispatchtouchevent(windowcallbackwrapper.java:69)                                                                                  @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:2330)                                                                                  @ android.view.view.dispatchpointerevent(view.java:8666)                                                                                  @ android.view.viewrootimpl$viewpostimeinputstage.processpointerevent(viewrootimpl.java:4123)                                                                                  @ android.view.viewrootimpl$viewpostimeinputstage.onprocess(viewrootimpl.java:3989)                                                                                  @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3544)                                                                                  @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3597)                                                                                  @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3563)                                                                                  @ android.view.viewrootimpl$asyncinputstage.forward(viewrootimpl.java:3680)                                                                                  @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3571)                                                                                  @ android.view.viewrootimpl$asyncinputstage.apply(viewrootimpl.java:3737)                                                                                  @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3544)                                                                                 @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java 

this cardview.xml i'm inflating:

<linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent">      <android.support.v7.widget.cardview         xmlns:card_view="http://schemas.android.com/apk/res-auto"         android:layout_width="match_parent"         android:layout_height="400dp"         card_view:cardelevation="5dp"         card_view:cardusecompatpadding="true"         card_view:layout_constrainttop_totopof="parent"         android:layout_margintop="8dp"         android:layout_marginleft="8dp"         card_view:layout_constraintleft_torightof="parent"         android:layout_marginstart="8dp">  <com.weiwangcn.betterspinner.library.material.materialbetterspinner                 android:id="@+id/zoneplanitineraryspinner"                 android:layout_width="240dp"                 android:layout_height="wrap_content"                 android:hint="select zone"                 app:met_floatinglabel="normal"                 android:layout_below="@id/deleteplanitinerary"                 android:layout_marginleft="20dp" />      </android.support.v7.widget.cardview>  </linearlayout> 

as possible, don't use multiple ids in 1 layout, android detects one, hence null object reference in stack trace.

according api guides:

an id need not unique throughout entire tree, should unique within part of tree searching (which may entire tree, it's best unique when possible).

https://developer.android.com/guide/topics/ui/declaring-layout.html#id

edit

since you're inflating new layouts same ids, try following:

view childview = getlayoutinflater().inflate(r.layout.cardview, null); materialbetterspinner spnr = childview.findviewbyid(r.id.zoneplanitineraryspinner); spnr.setonitemclicklistener(new adapterview.onitemclicklistener() {     @override      public void onitemclick(adapterview<?> parent, view view, int position, long id) {         // new cardview layout spinner code goes here...     }  }); 

you should use newly inflated layout find views id.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -