I have multiple XML files that need to be used by one Activity for its view, the Activity will load an XML file from the name passed to it when its created. These XML files will contain a set of UI elements such as buttons that will have a standardised name (ie UpBtn, DownBtn).
The views will be different (containing different button names) but I want to be able to check if a button of a specific name exists within the XML so that I can perform a specific action in the Activity.
Is there a way of doing this or will I have to resort to having an Activity per XML?
In your xml, provide your views with an unique id
In your activity, provided that you have already called setContentView() with one of the XML files, you can call findViewById() to find a particular view by its id:
If this view is present in the xml you provided, upBtnView will be the button you want; otherwise, upBtnView will be null, and you will know that it is not there in your layout.