本文整理汇总了Java中android.support.v4.app.Fragment.instantiate方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.instantiate方法的具体用法?Java Fragment.instantiate怎么用?Java Fragment.instantiate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.instantiate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onShortcutTap
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onShortcutTap(Uri uri) {
// Build root Uri from shortcut Uri
String rootUriString = uri.getScheme() + "://" + uri.getHost();
if (uri.getPort() != -1) {
rootUriString += ":" + uri.getPort();
}
rootUriString += "/";// important to end with "/"
Uri rootUri = Uri.parse(rootUriString);
Bundle args = new Bundle();
args.putParcelable(BrowserByNetwork.CURRENT_DIRECTORY, uri);
args.putString(BrowserByNetwork.TITLE
, uri.getLastPathSegment());
args.putString(BrowserByNetwork.SHARE_NAME, uri.getLastPathSegment());
Fragment f;
if (uri.getScheme().equals("smb")) {
f = Fragment.instantiate(getActivity(), BrowserBySmb.class.getCanonicalName(), args);
} else if (uri.getScheme().equals("upnp")) {
f = Fragment.instantiate(getActivity(), BrowserByUpnp.class.getCanonicalName(), args);
} else {
f = Fragment.instantiate(getActivity(), BrowserBySFTP.class.getCanonicalName(), args);
}
BrowserCategory category = (BrowserCategory) getActivity().getSupportFragmentManager().findFragmentById(R.id.category);
category.startContent(f);
}
示例2: onItemClick
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
//setPosition(position);
position = correctedPosition(position);
if(position ==-1)
return;
Season season = (Season) mBrowserAdapter.getItem(position);
Bundle args = new Bundle(3);
args.putLong(VideoStore.Video.VideoColumns.SCRAPER_SHOW_ID, season.getShowId());
args.putInt(VideoStore.Video.VideoColumns.SCRAPER_E_SEASON,
season.getSeasonNumber());
args.putString(SUBCATEGORY_NAME, season.getName());
Fragment f = Fragment.instantiate(mContext, BROWSER_SHOW, args);
BrowserCategory category = (BrowserCategory) getFragmentManager().findFragmentById(
R.id.category);
category.startContent(f);
mSelectedPosition=position;
}
示例3: onNavigationItemSelected
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Log.d(TAG, "onNavigationItemSelected "+itemPosition);
if (!mNavigationItemListenerActive) {
Log.d(TAG, "onNavigationItemSelected: listener is inactive, returning");
mNavigationItemListenerActive = true; // regular state is active, to get user feedback
return true;
}
BrowserCategory category = (BrowserCategory) getFragmentManager().findFragmentById(R.id.category);
Fragment f = Fragment.instantiate(getActivity(),MOVIE_CATEGORIES_CLASSES[itemPosition]);
category.loadFragmentAfterStackReset(f);
// Save the current position to the preferences
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
.putInt(KEY_ACTIONBAR_NAVIGATION_POSITION, itemPosition)
.commit();
return true;
}
示例4: switchToFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void switchToFragment(int willIndex, int oldIndex) {
boolean scrollView = willIndex == 0;
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment showFragment = fm.findFragmentByTag(mFragmentTags[willIndex]);
Fragment hideFragment = fm.findFragmentByTag(mFragmentTags[oldIndex]);
if (showFragment == null) {
boolean initVertical = getDefaultViewTypeOrientation(scrollView);
setViewTypeAndOrientation(scrollView, initVertical);
Bundle arg = new Bundle();
arg.putBoolean(ExampleFragment.KEY_VERTICAL, initVertical);
Class<? extends ExampleFragment> fragmentClass = scrollView ? ExampleScrollViewFragment.class : ExampleViewPagerFragment.class;
showFragment = Fragment.instantiate(this, fragmentClass.getName(), arg);
ft.add(R.id.fragmentContainer, showFragment, mFragmentTags[willIndex]);
} else {
setViewType(scrollView);
ft.show(showFragment);
}
if (hideFragment != null) {
ft.hide(hideFragment);
}
ft.commitAllowingStateLoss();
}
示例5: onShareOpen
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onShareOpen(WorkgroupShortcutAndServerAdapter.GenericShare share) {
final Uri uri = Uri.parse(share.getUri());
Bundle args = new Bundle();
args.putParcelable(BrowserByNetwork.CURRENT_DIRECTORY, uri);
args.putString(BrowserByNetwork.TITLE, share.getName());
args.putString(BrowserByNetwork.SHARE_NAME, uri.getLastPathSegment());
Fragment f;
if (uri.getScheme().equals("smb")) {
f = Fragment.instantiate(getActivity(), BrowserBySmb.class.getCanonicalName(), args);
} else {
f = Fragment.instantiate(getActivity(), BrowserByUpnp.class.getCanonicalName(), args);
}
BrowserCategory category = (BrowserCategory) getActivity().getSupportFragmentManager().findFragmentById(R.id.category);
category.startContent(f);
}
示例6: doTabChanged
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private FragmentTransaction doTabChanged(String tabId,
FragmentTransaction ft) {
TabInfo newTab = null;
for (int i = 0; i < mTabs.size(); i++) {
TabInfo tab = mTabs.get(i);
if (tab.tag.equals(tabId)) {
newTab = tab;
}
}
if (newTab == null) {
throw new IllegalStateException("No tab known for tag " + tabId);
}
if (mLastTab != newTab) {
if (ft == null) {
ft = mFragmentManager.beginTransaction();
}
if (mLastTab != null) {
if (mLastTab.fragment != null) {
// ft.detach(mLastTab.fragment);
ft.hide(mLastTab.fragment);
}
}
if (newTab != null) {
if (newTab.fragment == null) {
newTab.fragment = Fragment.instantiate(mContext,
newTab.clss.getName(), newTab.args);
ft.add(mContainerId, newTab.fragment, newTab.tag);
} else {
// ft.attach(newTab.fragment);
ft.show(newTab.fragment);
}
}
mLastTab = newTab;
}
return ft;
}
示例7: enterDirectory
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
protected void enterDirectory(MetaFile2 metaFile2) {
Bundle args = new Bundle(2);
args.putParcelable(CURRENT_DIRECTORY, metaFile2.getUri());
args.putString(TITLE, metaFile2.getName());
args.putBoolean(SHORTCUT_SELECTED, mShortcutSelected);
Fragment f = Fragment.instantiate(mContext, getClass().getCanonicalName(), args);
BrowserCategory category = (BrowserCategory) getFragmentManager().findFragmentById(R.id.category);
category.startContent(f);
}
示例8: navigateToFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void navigateToFragment(String fragmentName) {
Fragment fragment = Fragment.instantiate(getContext(), fragmentName);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
android.R.anim.fade_in, android.R.anim.fade_out);
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(fragmentName);
fragmentTransaction.commit();
}
示例9: getItem
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public Fragment getItem(int position) {
Bundle args = new Bundle();
if(useCodecsPerSpeed) {
args.putString(CodecsFragment.BAND_TYPE, (position % 2 == 0)? SipConfigManager.CODEC_WB : SipConfigManager.CODEC_NB );
args.putInt(CodecsFragment.MEDIA_TYPE, (position < 2)? CodecsFragment.MEDIA_AUDIO : CodecsFragment.MEDIA_VIDEO );
}else {
args.putString(CodecsFragment.BAND_TYPE, SipConfigManager.CODEC_WB );
args.putInt(CodecsFragment.MEDIA_TYPE, (position < 1)? CodecsFragment.MEDIA_AUDIO : CodecsFragment.MEDIA_VIDEO );
}
return Fragment.instantiate(mContext, mTabs.get(position), args);
}
示例10: doTabChanged
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private FragmentTransaction doTabChanged(final String tabId,
FragmentTransaction ft) {
TabInfo newTab = null;
for (int i = 0; i < mTabs.size(); i++) {
TabInfo tab = mTabs.get(i);
if (tab.tag.equals(tabId)) {
newTab = tab;
}
}
if (newTab == null) {
throw new IllegalStateException("No tab known for tag " + tabId);
}
FragmentTransaction fragmentTransaction = ft;
if (!newTab.equals(mLastTab)) {
if (fragmentTransaction == null) {
fragmentTransaction = mFragmentManager.beginTransaction();
}
if (mLastTab != null) {
if (mLastTab.fragment != null) {
fragmentTransaction.detach(mLastTab.fragment);
}
}
if (newTab.fragment == null) {
newTab.fragment = Fragment.instantiate(mContext,
newTab.clss.getName(), newTab.args);
newTab.fragment.setRetainInstance(mIsRetanedFragments);
fragmentTransaction.add(mContainerId, newTab.fragment,
newTab.tag);
} else {
fragmentTransaction.attach(newTab.fragment);
}
mLastTab = newTab;
}
return fragmentTransaction;
}
示例11: showFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void showFragment(Class<? extends Fragment> fragmentClass) {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.container);
if (fragment == null) {
fragment = Fragment.instantiate(this, fragmentClass.getName());
getSupportFragmentManager().beginTransaction().add(R.id.container, fragment).commitNow();
}
}
示例12: onReceive
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Cover.LAUNCH_CONTENT_BROWSER_INTENT)) {
Fragment f = Fragment.instantiate(BrowserActivity.this,
intent.getStringExtra(FRAGMENT_NAME), intent.getBundleExtra(FRAGMENT_ARGS));
BrowserCategory category = (BrowserCategory) getSupportFragmentManager().findFragmentById(
R.id.category);
category.startContent(f);
}
}
示例13: getFragmentByName
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public Fragment getFragmentByName(Class<?> screen){
return Fragment.instantiate(context, screen.getName());
}
示例14: getItem
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public Fragment getItem(int position) {
return Fragment.instantiate(mContext, mFragments[position].getName());
}
示例15: onCreate
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle data) {
super.onCreate(data);
setContentView( R.layout.scanner );
barcodeScannerView = ( DecoratedBarcodeView)findViewById(R.id.barcode_scanner);
barcodeScannerView.setTorchListener(this);
fab = (FloatingActionButton) findViewById(R.id.fab);
// if the device does not have flashlight in its camera,
// then remove the switch flashlight button...
this.light = false;
if ( !hasFlash() ) {
// fab.setVisibility( View.GONE );
}
if( data == null ){
data = getIntent().getExtras();
}
this.data = data.getBundle( ARG_FRAGMENT_BOTTOM_DATA );
this.fragmentBottomName = data.getString( ARG_FRAGMENT_BOTTOM_NAME );
if( this.fragmentBottomName != null ){
FragmentTransaction trasition = getSupportFragmentManager().beginTransaction();
Fragment fragment = Fragment.instantiate( this, fragmentBottomName );
fragment.setArguments( this.data );
if( getSupportFragmentManager().findFragmentById( R.id.content ) == null ){
trasition.add( R.id.content, fragment );
}
else {
trasition.replace( R.id.content, fragment );
}
trasition.commit();
}
capture = new CaptureManager( this, barcodeScannerView );
capture.initializeFromIntent( getIntent(), data );
capture.decode();
}