我使用选项卡构建自己的网络浏览器。我的问题是,当我关闭一个选项卡并返回另一个选项卡时,如果我单击当前选项卡,那么我会得到关闭选项卡的内容。这是我的代码:
private void addMethod() {
//tring webSiteName = getHost("http://www.google.com");
Intent openBrowser = new Intent();
openBrowser.setClass(this, WebBrowser.class);
tabHost.addTab(tabHost.newTabSpec("http://www.google.gr" + Integer.toString(z)).setIndicator("ΚΑΡΤΕΛΑ ").setContent(openBrowser));
tabHost.setCurrentTab(z);
Log.d("z",Integer.toString(z));
++z;
}
private void deleteMethod() {
// Since we can't really delete a TAB
// We hide it
int position = tabHost.getCurrentTab();
Log.d("Position",Integer.toString(position));
if (position != 0 ) {
tabHost.getCurrentTabView().setVisibility(1);
tabHost.setCurrentTab(position-1);
}
else if(position== z){
tabHost.getCurrentTabView().setVisibility(1);
tabHost.setCurrentTab(position+1);
}
Log.d("Z val in delete()",Integer.toString(z));
if(position >0)
{
tabHost.getCurrentTabView().setVisibility(View.GONE);
tabHost.setCurrentTab(position+1);
z-=1;
if(z<0)
z=0;
}
else if(position == 0)
{
tabHost.getCurrentTabView().setVisibility(View.GONE);
tabHost.setCurrentTab(position+1);
z=0;
}
else if(position == z)
{
tabHost.getCurrentTabView().setVisibility(View.GONE);
tabHost.setCurrentTab(z-1);
Log.d("Z value in final","lol");
Log.d("Pos",Integer.toString(position));
Log.d("z pos",Integer.toString(z));
z--;
}