I'm trying to make it so the user can add/delete tabs. When a new tab is added, the tab's content is set to TBrowser.class.
Below is how the tabs are made:
private void addMethod() { ++i; Intent TBrowser = new Intent(); TBrowser.setClass(this, TBrowser.class); tabHost.addTab(tabHost.newTabSpec(Integer.toString(i)).setIndicator("Tab").setContent(TBrowser)); }
TBrowser.class has the contentView of a layout with a WebView in it basically.
So far it works fine, except I can only control the WebView of the most recently created tab, (eg refresh, go back etc). So my question is how can I control all the WebViews? I've spent a pretty silly amount of time trying to get this to work so I really appreciate any help! Let me know if there's anything else you need me to supply.
(How I'm trying to find the webviews and refresh for example:)
WebView mWebView = (WebView) TBrowser.mWebView; mWebView.refresh();
I tried setting a tag to the webviews as they are made and finding the webview by tag but that only seemed to work for one and after that it would just go back to only working for the newly created one...
--Edit --
With the help of sushildlh's answer I managed to control the 1st tab even after a new tab was made.. I connected the globally defined WebView's to the WebViews inflated from the TBrowser class by the following:-
webViews[p] = TBrowser.mWebView; p++;
and I did that every time a new tab was added.. But now it only works for the first tab because I think it cannot find TBrowser.mWebView, is there a way to do that so it will find it?
-- --
Thanks in advance :)
1 Answers
Answers 1
Create N number of WebView globally like this .....
private WebView webViews[]=new WebView[10],webview; private int i=0,postions[]=new int[10];
And maintain your webView and i value with your new tab ....
Example:- When you create new tab increment i value and access anothers webViews[i] object......
OR when you switch your tab store i value into some array and change the i value according to your Tab and use that webViews...
and for the backpress
@Override public void onBackPressed() { // maintain you webviews back if(webviews[i].canGoBack()){ webview[i].goBack(); }else { //delete the last tab and switch to last accessed Tab and webview with i..... //check the size of the int array if it's size is 0 than exit the app } }
Note:- Problem is accessing locally WebView in all tab......
0 comments:
Post a Comment