1

I use these lines of code to extract and parse the xml layout.

    Activity activity = MyClassName.this;
    Resources res = activity.getResources();
    XmlResourceParser xpp = res.getXml(R.layout.MyXmlName);
    //...parse...

It can parse all tags and attributes from the xml, the problem is it can only extract the very first loaded version of the xml.

When I dynamically change attributes like myButton.setText("new_name"), the parser always returns the earliest button name. Same thing, nothing else will change in the xml if anything is modified after loading.

When I dynamically set visibility, which is an attribute not existed in the original xml file, it only extracts the earliest xml without the new attribute. I hope it can be shown too.

Is my code or my approach wrong? Or is parsing dynamic xml impossible? If so, is there an alternative way to get the dynamic layout?

user6219476
  • 89
  • 1
  • 11
  • Maybe it's best to traverse from the root view; locate one targeted id of views(or traverse every view); and get all attribute like text based on the view. I've succeeded getting a button's dynamic text this way. Considering a large project with a lot of views, is it do-able? – user6219476 Jul 11 '17 at 21:15

0 Answers0