英文:
How to create a view that shows either spinner or edittext on condition?
问题
我使用了recyclerView和一些cardViews,其中包含一些editTexts,例如:
现在我想根据提供给viewHolder的数据,以编程方式显示spinner或editText。
我已经阅读了关于自定义视图的官方文档,但我不确定自己实现onDraw、onMeasure等是否是正确的方法。
我也在研究ViewGroup,但还没有完全理解。
谢谢
英文:
I use recyclerView and a few cardViews with some editTexts on it, for example:
And now I want to modify the design to programmatically display either spinner or editText based on data given to viewHolder.
I have read the official doc about the custom view, but I am not sure if self-implementing onDraw, onMeasure, ..., will be the right way.
I'm also looking into ViewGroup but have not understood it yet.
Thanks
答案1
得分: 1
有一个简单的方法来做到这一点。您不一定需要复杂的自定义视图。您可以在UI上放置Spinner
和EditText
,然后只需将您当前不需要的视图设置为android:visibility=gone
,将需要的视图设置为android:visibility=visible
。
英文:
There's a simple way to do this. You don't necessarily need some complex custom view for this. You can just put both Spinner
and EditText
on your UI, then just android:visibility=gone
the view that you don't need currently, and android:visibility=visible
the one you need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论