Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i assume, you can go with <a href="http://docs.oracle.com/javase/tutorial/reflect/" rel="nofollow">reflection</a> and lots of iteration.</p> <p>First you want all your statics in the R.layout class - then you obtain their values and compare them to the <code>View.getId()</code> and in a last step you retrieve the fields name.</p> <p>but: the name will only contain layout-files name (in your example <code>main</code>) and not the full path to it, even though you could have duplicate layouts with the same name, e.g. for landscape/portrait mode etc</p> <p>I never tried something like that and I'm not sure if this works out, because i don't know if your testenvironment can access your R file without errors, but that's the way you could go</p> <p>edit: just adding some sample code that should do the job, works from within the app - as said i'm unsure about your framework and the way you access r</p> <pre><code>R.layout layout = new R.layout(); Map&lt;Integer, String&gt; id2name = new HashMap&lt;Integer, String&gt;(); for (Field f : layout.getClass().getDeclaredFields()) { try { id2name.put(f.getInt(layout), f.getName()); Log.i("Layout", f.getInt(layout) + "," + f.getName()); } catch (IllegalArgumentException e) { //oops Log.e("Layout", "", e); } catch (IllegalAccessException e) { //oops Log.e("Layout", "", e); } } for (Entry&lt;Integer, String&gt; e:id2name.entrySet()) { if (findViewById(e.getKey()) != null) { Log.i("Layout:", "found: " + e.getValue() + ";" + e.getKey()); }else { Log.i("Layout:", "not found: " + e.getValue()+ ";" + e.getKey()); } } </code></pre> <p>note that there will be no view found unless layouting is done (findViewById() is null if you call to early)</p> <p>of course you can go the other way around and search down the view tree by checking if a layout is instance of a ViewGroup and iterate over its childviews and compare each's id to the ids in the map</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload