views:

109

answers:

2

I am using WebView in an ActivityGroup and it will throw an exception if WebView show Dialog and complain the activity is not valid. But it's okay if I set the context of the WebView to the TOP activity. So I wish to know how to set the context in the layout xml ?

A: 

So I wish to know how to set the context in the layout xml ?

That's not possible. Though, I have some experience with ActivityGroup, so I know how to solve this problem:

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

Then, when you need a context in order to show a dialog or a Toast or whatever, you use YourActivityGroup.self.

Cristian
But if I get my Spinner with findViewById(...), I can't set the context - how can I achieve that? In combination with ActivityGroup, the spinner doesn't work, unfortunately...
swalkner
I don't know why you would want to set the context to the spinner... is it giving you problems?
Cristian
yes - it asks me if my activity is running: "Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44ed8338 is not valid; is your activity running?"
swalkner
A: 

You can use layoutinflater to achieve this:

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

Hope that helps. for dialog you can just change context from this to

this.getParent()
gunagunaistrimuda