[英]Tab navigation after validation using tabhost
I am new to using TabHost and currently trying to implement a validation check when moving between tabs. 我是使用TabHost的新手,并且当前正在尝试在选项卡之间移动时实施验证检查。 My problem comes with the use of
我的问题来自于
onTabChanged(String tabId)
as i need to know what the selected tab is so as, if validation fails, i can redirect to the previous tabs. 因为我需要知道选定的选项卡是什么,因此,如果验证失败,我可以重定向到先前的选项卡。 How can i get the id's so as to know the current tab and redirect to previous tab?
我如何获取ID以了解当前标签并重定向到上一个标签?
My tabhost script is: 我的tabhost脚本是:
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
public class Invoice3 extends FragmentActivity implements OnTabChangeListener {
private FragmentTabHost mTabHost;
String check = null;
ShowAlert alert = new ShowAlert();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
mTabHost.addTab(
mTabHost.newTabSpec("tab1").setIndicator("Client", null),
clientFragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("tab2").setIndicator("Products", null),
productsFragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("tab3").setIndicator("Confirm", null),
confirmFragmentTab.class, null);
}
public void onTabChanged(String tabId) {
//Log.d(TAG, "onTabChanged(): tabId=" + tabId);
check = GlobalApp.data().value;
if (<check if 2nd tab has been selected>) {
if(check == "False")
{
<redirect to 1st tab>
}
}
}
}
}
You can save in a variable the id of the current tab, and go back to it. 您可以将当前选项卡的ID保存在变量中,然后返回到它。 Something like this should work.
这样的事情应该起作用。
String prevTab = null;
public void onTabChanged(String tabId) {
//Log.d(TAG, "onTabChanged(): tabId=" + tabId);
check = GlobalApp.data().value;
if (<check if 2nd tab has been selected>) {
if(check == "False")
{
if (prevTab != null) {
// redirect to prevTab
}
} else {
prevTab = tabId;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.