如何在安卓中创建一个类型为Activity的列表。

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

How to create a List which of type Activity in android

问题

如何创建一个类型为Activity的List?

英文:
List<Activity> allowedActivites = new ArrayList<>();
allowedActivites.add(SplashActivity.class);
allowedActivites.add(SubscriptionActivity.class);

How to create a List which is of type activity?

答案1

得分: 2

你尝试添加到列表的项目是类。如果你想要一个扩展Activity的类的列表,类型是List<Class<? extends Activity>>

所以你可以这样做:

List<Class<? extends Activity>> allowedActivites = new ArrayList<>();
allowedActivites.add(SplashActivity.class);
allowedActivites.add(SubscriptionActivity.class);

只要它们是Activity的子类。

英文:

The items that you're trying to add to your list are classes. If you want a list of classes that extend Activity, the type is List<Class<? extends Activity>>.

So you can do

List<Class<? extends Activity>> allowedActivites = new ArrayList<>();
allowedActivites.add(SplashActivity.class);
allowedActivites.add(SubscriptionActivity.class);

as long as those are subclasses of Activity.

huangapple
  • 本文由 发表于 2020年7月29日 02:49:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63140910.html
匿名

发表评论

匿名网友

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

确定