如何在安卓中获取字段名

huangapple 未分类评论52阅读模式
英文:

How to get field name in android

问题

我正在创建一个相机应用,希望记录有关相机状态的信息。现在我正在使用:

Log.i("AF状态", String.valueOf(result.get(CaptureResult.CONTROL_AF_STATE)));

它返回类似以下的值:

I/AF状态: 1

这很难阅读,我想知道是否有一种方法可以记录这些数字代表的字段名称,例如:

I/AF状态: CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED
英文:

I'm creating camera app and I want to log infos about camera state. Now I'm using:

Log.i("AF state", String.valueOf(result.get(CaptureResult.CONTROL_AF_STATE)));

It returns values like:

I/AF state: 1

It is hard to read and I'm curious if there is a way to log field names that these numbers represent, for example:

I/AF state: CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED

答案1

得分: 0

你可以使用 getName()

Log.i("AF 状态", result.get(CaptureResult.CONTROL_AF_STATE).getName());

来源:Android 开发者文档

返回一个驼峰式、点分隔的名称格式,类似于:

"root.section[.subsections].name"。
英文:

You can use getName()

Log.i("AF state", result.get(CaptureResult.CONTROL_AF_STATE).getName());

from Android Developer Docs

Return a camelCase, period separated name formatted like:

"root.section[.subsections].name".

huangapple
  • 本文由 发表于 2020年4月10日 21:21:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61141187.html
匿名

发表评论

匿名网友

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

确定