Sometimes users require getting the coded values of the field in Android Runtime. It is a little complicated to get to the Coded domain from the geodatabase.
Following is an example code to get it. This is for offline geodatabase(Runtime Content), same can be done for geodatabase coming from Service using ServiceFeatureTable class.
<SPAN class="comment token">//Open the geodatabase file</SPAN>
String path <SPAN class="operator token">=</SPAN> <SPAN class="string token">"/storage/emulated/0/testdomainclass.geodatabase"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// path to the offline runtime content on android device</SPAN>
geodatabase <SPAN class="operator token">=</SPAN> null<SPAN class="punctuation token">;</SPAN>
geodatabase <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Geodatabase</SPAN><SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
geodatabase<SPAN class="punctuation token">.</SPAN><SPAN class="token function">loadAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// add feature layer from geodatabase to the ArcGISMap</SPAN>
geodatabaseFeatureTable <SPAN class="operator token">=</SPAN> geodatabase<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getGeodatabaseFeatureTable</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"points"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// name of the feature class insife the runtime content</SPAN>
geodatabaseFeatureTable<SPAN class="punctuation token">.</SPAN><SPAN class="token function">loadAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Field field <SPAN class="operator token">=</SPAN> geodatabaseFeatureTable<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getField</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"name"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// name of the field for which the domain is created</SPAN>
Domain domain <SPAN class="operator token">=</SPAN> field<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getDomain</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
CodedValueDomain codedValueDomain <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>CodedValueDomain<SPAN class="punctuation token">)</SPAN> domain<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
List<SPAN class="operator token"><</SPAN>CodedValue<SPAN class="operator token">></SPAN> codedvaluelist <SPAN class="operator token">=</SPAN> codedValueDomain<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCodedValues</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
In the above example, codedvaluelist object will contain the name and the code which can be retrieved using following code:
codedvaluelist<SPAN class="punctuation token">.</SPAN><SPAN class="token function">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">getName</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//name of codedvalue at 0 index</SPAN>
codedvaluelist<SPAN class="punctuation token">.</SPAN><SPAN class="token function">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCode</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// code of codedvalue at 0 index</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>