do android views have equivalent css class selectors? r.id usable multiple views? hide group of views independent of position in layout tree.
i think need iterate through of views in layout, looking android:id want. can use view setvisibility() change visibility. use view settag() / gettag() instead of android:id mark views want handle. e.g., following code uses general purpose method traverse layout:
// top view in layout. final view root = getwindow().getdecorview().findviewbyid(android.r.id.content); // create "view handler" hide given view. final viewhandler setviewgone = new viewhandler() { public void process(view v) { // log.d("viewhandler.process", v.getclass().tostring()); v.setvisibility(view.gone); } }; // hide view in layout id equals r.id.textview1. findviewsbyid(root, r.id.textview1, setviewgone); /** * simple "view handler" interface can pass java method. */ public interface viewhandler { public void process(view v); } /** * recursively descends layout hierarchy starting @ specified view. viewhandler's * process() method invoked on view matches specified id. */ public static void findviewsbyid(view v, int id, viewhandler viewhandler) { if (v.getid() == id) { viewhandler.process(v); } if (v instanceof viewgroup) { final viewgroup vg = (viewgroup) v; (int = 0; < vg.getchildcount(); i++) { findviewsbyid(vg.getchildat(i), id, viewhandler); } } }
Comments
Post a Comment