本文整理汇总了Java中android.app.ActionBar.Tab类的典型用法代码示例。如果您正苦于以下问题:Java Tab类的具体用法?Java Tab怎么用?Java Tab使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tab类属于android.app.ActionBar包,在下文中一共展示了Tab类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTabSelected
import android.app.ActionBar.Tab; //导入依赖的package包/类
/**
* @brief Method called when the tab is selected
* @param tab
* @param ft
* @details Method called when the tab is selected
*/
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// Check if the fragment is already initialized
mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
if (mFragment == null) {
// If not, instantiate and add it to the activity
mFragment = Fragment.instantiate(
mActivity, mClass.getName());
//mFragment.setProviderId(mTag); // id for event provider
setmTransaction(ft);
ft.add(android.R.id.content, mFragment, mTag);
} else {
// If it exists, simply attach it in order to show it
setmTransaction(ft);
ft.attach(mFragment);
}
}
示例2: onTabUnselected
import android.app.ActionBar.Tab; //导入依赖的package包/类
/**
* @brief Method called when the tab is unselected
* @param tab
* @param ft
* @details Method called when the tab is unselected
*/
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
// Detach the fragment, because another one is being attached
ft.detach(mFragment);
}
}
示例3: onCreate
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this.setContentView(R.layout.layout_main);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);
Tab customerTab = actionBar.newTab().setText(
this.getResources().getString(R.string.customer_tab));
final Fragment customerPackageList = new CustomerPackageFragment(this);
customerTab.setTabListener(new PackageTabListener(customerPackageList));
Tab systemTab = actionBar.newTab().setText(
this.getResources().getString(R.string.system_tab));
final Fragment systemPackageList = new SystemPackageFragment(this);
systemTab.setTabListener(new PackageTabListener(systemPackageList));
actionBar.addTab(customerTab);
actionBar.addTab(systemTab);
}
示例4: onTabSelected
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
public void onTabSelected(final Tab tab, final FragmentTransaction ft) {
if (fragment == null) {
fragment = Fragment.instantiate(MainActivity.this, clazz.getName());
ft.replace(R.id.fragment_container, fragment, clazz.getSimpleName());
} else if (fragment.isDetached()) {
ft.attach(fragment);
}
currentFragment = fragment;
if (searchView != null) {
searchView.setOnQueryTextListener(null);
searchView.setQuery(null, false);
searchView.setOnQueryTextListener(createSearchQueryListener());
}
}
示例5: onTabSelected
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Fragment fragment = null;
/*if (tab.getPosition() == 0) {
fragment = new AlertsFragment();
}
else if (tab.getPosition() == 1) {
fragment = new ConditionsFragment();
}
else if (tab.getPosition() == 2) {
fragment = new ForecastFragment();
}*/
if (tab.getPosition() == 0) {
fragment = new ConditionsFragment();
}
else if (tab.getPosition() == 1) {
fragment = new ForecastFragment();
}
if (fragment != null) {
mCurrentFragment = fragment;
getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
}
}
示例6: onTabSelected
import android.app.ActionBar.Tab; //导入依赖的package包/类
public void onTabSelected(Tab tab, FragmentTransaction ft) {
int tabSelected = tab.getPosition();
Log.d(TAG, "Tab selected " + tabSelected + " current act " + currentActivityNo);
if (canNavigateTo(tabSelected)){
viewPager.setCurrentItem(tabSelected);
currentActivityNo = tabSelected;
this.stopReading();
WidgetFactory currentWidget = (WidgetFactory) apAdapter.getItem(currentActivityNo);
currentWidget.resetTimeTracking();
}
else{
Runnable setPreviousTab = new Runnable(){
@Override
public void run() {
UIUtils.showAlert(CourseActivity.this, R.string.sequencing_dialog_title, R.string.sequencing_section_message);
actionBar.setSelectedNavigationItem(currentActivityNo);
viewPager.setCurrentItem(currentActivityNo);
}
};
Handler handler=new Handler();
handler.post(setPreviousTab);
}
}
示例7: onResume
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
// Select proper stack
ActionBar actionBar = getActionBar();
if (actionBar != null) {
Tab tab = actionBar.getSelectedTab();
Stack<String> backStack = backStacks.get(tab.getTag());
if (!backStack.isEmpty()) {
// Restore topmost fragment (e.g. after application switch)
String tag = backStack.peek();
Fragment fragment = getFragmentManager().findFragmentByTag(tag);
if (fragment.isDetached()) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.attach(fragment);
ft.commit();
}
}
}
}
示例8: onPause
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
protected void onPause() {
super.onPause();
// Select proper stack
ActionBar actionBar = getActionBar();
if (actionBar != null) {
Tab tab = actionBar.getSelectedTab();
Stack<String> backStack = backStacks.get(tab.getTag());
if (!backStack.isEmpty()) {
// Detach topmost fragment otherwise it will not be correctly
// displayed
// after orientation change
String tag = backStack.peek();
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment fragment = getFragmentManager().findFragmentByTag(tag);
ft.detach(fragment);
ft.commit();
}
}
}
示例9: onTabReselected
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// Select proper stack
Stack<String> backStack = backStacks.get(tab.getTag());
if (backStack.size() > 1) {
// ft.setCustomAnimations(R.anim.slide_from_right,
// R.anim.slide_to_left);
// Clean the stack leaving only initial fragment
while (backStack.size() > 1) {
// Pop topmost fragment
String tag = backStack.pop();
Fragment fragment = getFragmentManager().findFragmentByTag(tag);
// Remove it
ft.remove(fragment);
}
}
showFragment(backStack, ft);
}
示例10: onActivityResult
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Select proper stack
ActionBar actionBar = getActionBar();
if (actionBar != null) {
Tab tab = actionBar.getSelectedTab();
Stack<String> backStack = backStacks.get(tab.getTag());
Fragment fragment = getFragmentManager().findFragmentByTag(backStack.peek());
// Passing the Activity Result for the child fragment
if (fragment != null) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}
}
示例11: addFragment
import android.app.ActionBar.Tab; //导入依赖的package包/类
public void addFragment(Fragment fragment) {
// Select proper stack
ActionBar actionBar = getActionBar();
if (actionBar != null) {
Tab tab = actionBar.getSelectedTab();
Stack<String> backStack = backStacks.get(tab.getTag());
FragmentTransaction ft = getFragmentManager().beginTransaction();
// Get topmost fragment
String tag = backStack.peek();
Fragment top = getFragmentManager().findFragmentByTag(tag);
if (top != null) {
ft.detach(top);
}
// Add new fragment
addFragment(fragment, backStack, ft);
ft.commit();
}
}
示例12: onKeyDown
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
ActionBar actionBar = getActionBar();
if (actionBar != null) {
Tab tabSelected = actionBar.getSelectedTab();
if (tabSelected.getText().equals(getString(R.string.tab__list))) {
finish();
moveTaskToBack(true);
} else {
getActionBar().selectTab(actionBar.newTab().setTag(TabType.LIST).setText(R.string.tab__list).setTabListener(this));
}
}
}
return super.onKeyDown(keyCode, event);
}
示例13: onCreate
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar ab = getActionBar();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Add tabs
Tab tab = ab.newTab()
.setText(R.string.agendas)
.setTabListener(new CalendarMuteTabListener<>(this, TAG_TAB_CALENDARS, CalendarsFragment.class));
ab.addTab(tab);
tab = ab.newTab()
.setText(R.string.actions)
.setTabListener(new CalendarMuteTabListener<>(this, TAG_TAB_ACTIONS, ActionsFragment.class));
ab.addTab(tab);
if(ACTION_SHOW_ACTIONS.equals(getIntent().getAction()))
ab.setSelectedNavigationItem(1); // Show actions tab
if(savedInstanceState != null && savedInstanceState.containsKey(KEY_SAVED_CURRENT_TAB))
ab.setSelectedNavigationItem(savedInstanceState.getInt(KEY_SAVED_CURRENT_TAB));
// Start service
MuteService.startIfNecessary(this);
}
示例14: addTab
import android.app.ActionBar.Tab; //导入依赖的package包/类
public void addTab(Tab tab, Class<?> clss, Event event){
TabInfo info = new TabInfo(clss, event);
tab.setTag(info);
tab.setTabListener(this);
mTabs.add(info);
mFragments.add(EventFragment.newInstance(event));
mActionBar.addTab(tab);
notifyDataSetChanged();
}
示例15: onTabSelected
import android.app.ActionBar.Tab; //导入依赖的package包/类
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
Object tag = tab.getTag();
for (int i = 0; i<mTabs.size(); i++){
if (mTabs.get(i) == tag){
mViewPager.setCurrentItem(i);
}
}
}