我使用以下链接创建了动态Tabhost
http://www.pocketmagic.net/?p=1132
我已使用WebView更改内容,如下所示
ts3.setContent(new TabHost.TabContentFactory(){
public View createTabContent(String tag)
{
LinearLayout panel = new LinearLayout(sActiveContext);
panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
panel.setOrientation(LinearLayout.VERTICAL);
WebView webview=new WebView(sActiveContext);
panel.addView(webview);
return panel;
}
});
webview.goback()实现如下
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(event.getAction() == KeyEvent.ACTION_DOWN)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(webview.canGoBack())
webview.goBack();
else
//alert
return true;
}
}
return super.onKeyDown(keyCode, event);
}
always i'm getting alert msg only
。我错过了什么?
注意:从客户端传递的标签和标题数量。上面的代码在服务器端。
答案 0 :(得分:0)
我用WebView解决了这个goback问题。我从tabhost的当前选项卡中获取了当前的webview。现在工作正常
public static WebView getCurrentWebView()
{
if(sTabHost!=null)
{
View view=sTabHost.getCurrentView();
if(view!=null)
{
View child=((ViewGroup)view).getChildAt(0);
for(int i=0; i<((ViewGroup)child).getChildCount(); i++) {
View nextChild = ((ViewGroup)child).getChildAt(i);
if(nextChild!=null)
{
String type=nextChild.getClass().toString();
if(type!=null && !type.equals("") && type.equals("class android.webkit.WebView"))
{
sCurrentWebView=(WebView) (((ViewGroup)child).getChildAt(i));
break;
}
}
}
}
}
return sCurrentWebView;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(event.getAction() == KeyEvent.ACTION_DOWN)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
WebView view=getCurrentWebView();
if(view!=null && view.canGoBack())
view.goBack();
else
//alert
return true;
}
}
return super.onKeyDown(keyCode, event);
}