Tara
Tara

Reputation: 700

SetId() and then findviewById in java programmatically issue

Hi i am trying to setId programmatically, but the issue is how to find that id after setting it in java. i am working in fragments (Viewpager)and here is my code below.

property=new SearchableSpinner(getActivity());
city.setId(R.id.citybuy);
town.setId(R.id.townbuy);
property.setId(R.id.propertybuy);

 city = (SearchableSpinner) this.view.findViewById(R.id.citybuy);
  town = (SearchableSpinner) this.view.findViewById(R.id.townbuy);
 property = (SearchableSpinner) this.view.findViewById(R.id.propertybuy);

and it didn't find id and shows NullPointerException and if i set id through XML then it shows this error:

java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class gr.escsoft.michaelprimez.searchablespinner.SearchableSpinner$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy..This view's id is id/city_wanted. Make sure other views do not use the same id

Though id's are different in all fragments XML

Upvotes: 0

Views: 1654

Answers (1)

Abdul Waheed
Abdul Waheed

Reputation: 4678

what I believe you are setting id to the view in xml and also now you are setting the same id again to the same view.

Upvotes: 1

Related Questions