如何根据条件创建一个视图,该视图可以显示旋转器或编辑文本?

huangapple go评论74阅读模式
英文:

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上放置SpinnerEditText,然后只需将您当前不需要的视图设置为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.

huangapple
  • 本文由 发表于 2023年7月4日 21:57:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定