如何使用Android常量值作为常量名称?

时间:2018-08-14 22:30:29

标签: android google-places-api google-places

我正在Android上使用Place API。如文档所示,对于每种类型的位置,there is a code

public static final int TYPE_RESTAURANT Constant Value: 79

比较时,如何在代码中直接使用String表示形式?

例如:
if plc = Place.TYPE_RESTAURANT then showToast();

我可以手动创建一个常量列表,但是应该有一种更好的直接方法。

谢谢

1 个答案:

答案 0 :(得分:0)

我添加了

import com.google.android.gms.location.places.Place;

然后使用

Place.TYPE_RESTAURANT

进行比较。

if (plac.getPlace().getPlaceTypes().contains(Place.TYPE_RESTAURANT)) { yourcode here
                                }