gpt4 book ai didi

java - SetId(),然后在java中以编程方式findviewById

转载 作者:行者123 更新时间:2023-12-02 12:00:21 26 4
gpt4 key购买 nike

嗨,我正在尝试以编程方式 setId,但问题是如何在 java 中设置后找到该 id。我在 fragments (Viewpager) 工作下面是我的代码。

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);

但没有找到id并显示NullPointerException如果我 set id通过XML然后它显示这个 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

尽管id's全部不同fragments XML

最佳答案

我相信您正在将 id 设置为 xml 中的 View ,现在您又将相同的 id 设置为同一 View 。

关于java - SetId(),然后在java中以编程方式findviewById,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47308468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com