Android: how to set context for presentation in xml layout?

I am using a WebView in an ActivityGroup, and it will throw an exception if the WebView displays Dialog and reports that the action is invalid. But this is normal if I set the WebView context to TOP activity. So, I want to know how to set context in xml layout?

+3
source share
2 answers

To achieve this, you can use layoutinflater:

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.yourLayoutName, null);
this.theSpinner = (Spinner) viewToLoad.findViewById(R.id.Spinny);
this.setContentView(viewToLoad );

Hope this helps. for dialogue you can just change the context from this to

this.getParent()
+2
source

So, I want to know how to set context in xml layout?

. , ActivityGroup, , :

// in your ActivityGroup...
public class YourActivityGroup extends ActivityGroup{
    public static YourActivityGroup self;
    public YourActivityGroup(){
        self = this;
        // the rest of your code here
    }
}

, , Toast - , YourActivityGroup.self.

0

Source: https://habr.com/ru/post/1764626/


All Articles