本文整理汇总了Java中android.support.v4.app.Fragment类的典型用法代码示例。如果您正苦于以下问题:Java Fragment类的具体用法?Java Fragment怎么用?Java Fragment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Fragment类属于android.support.v4.app包,在下文中一共展示了Fragment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getItem
import android.support.v4.app.Fragment; //导入依赖的package包/类
@Override
public Fragment getItem(int index) {
switch (index) {
case 0:
// System notifications fragment activity
return new SystemFragment();
case 1:
// Application notifications fragment activity
return new AppsFragment();
case 2:
// Stats fragment activity
return new StatsFragment();
case 3:
// Settings fragment activity
return new StatsFragment();
}
return null;
}
示例2: setUseExpandableHeaders
import android.support.v4.app.Fragment; //导入依赖的package包/类
public void setUseExpandableHeaders(boolean enabled) {
if (isViewPager()) {
Collection<Fragment> fragments = mPagerAdapter.getAllCachedFragments();
for (Fragment f : fragments) {
((SettingsFragment) f).setUseExpandableHeaders(enabled);
}
} else {
setup.setUseExpandableHeaders(enabled);
getArguments().putParcelable("setup", setup);
if (mItems != null) {
if (!enabled) {
FastAdapterUtil.expand(mFastItemAdapter);
}
SettingsUtil.updateExpandableHeaders(mItems, enabled);
SettingsUtil.setExpandedState(mItems, true);
mFastItemAdapter.notifyAdapterDataSetChanged();
}
}
}
示例3: newInstance
import android.support.v4.app.Fragment; //导入依赖的package包/类
public static Fragment newInstance(Cursor c, int position) {
final Fragment f = new PhotoViewFragment();
final Bundle b = new Bundle();
int photoID = c.getInt(0);
b.putInt(MediaSetUtils.PHOTO_ID, photoID);
String path = c.getString(1);
b.putString(MediaSetUtils.PHOTO_PATH, path);
String type = c.getString(2);
b.putInt(TYPE, type == null ? MediaSetUtils.TYPE_IMAGE :
(type.startsWith("video") ? MediaSetUtils.TYPE_VIDEO : MediaSetUtils.TYPE_IMAGE));
b.putInt(CURRENT_POSITION, position);
f.setArguments(b);
return f;
}
示例4: onClick
import android.support.v4.app.Fragment; //导入依赖的package包/类
@Override
public void onClick(Fragment currentFragment, final RongExtension extension) {
String[] permissions = {Manifest.permission.RECORD_AUDIO};
if (!PermissionCheckUtil.requestPermissions(currentFragment, permissions)) {
return;
}
if (SpeechUtility.getUtility() == null) {
SpeechUtility.createUtility(extension.getContext().getApplicationContext(), SpeechConstant.APPID + "=581f2927"); //初始化
}
recognizerView = new RecognizerView(extension.getContext());
recognizerView.setResultCallBack(new IRecognizedResult() {
@Override
public void onResult(String data) {
Editable editable = extension.getInputEditText().getText();
String str = editable.toString() + data;
extension.getInputEditText().setText(str);
extension.getInputEditText().setSelection(str.length());
}
@Override
public void onClearClick() {
extension.getInputEditText().setText("");
}
});
extension.addPluginPager(recognizerView);
}
示例5: handleActivity
import android.support.v4.app.Fragment; //导入依赖的package包/类
private static void handleActivity(Activity activity) {
if (activity instanceof HasSupportFragmentInjector) {
AndroidInjection.inject(activity);
}
if (activity instanceof FragmentActivity) {
((FragmentActivity) activity).getSupportFragmentManager()
.registerFragmentLifecycleCallbacks(
new FragmentManager.FragmentLifecycleCallbacks() {
@Override
public void onFragmentCreated(FragmentManager fm, Fragment f,
Bundle savedInstanceState) {
if (f instanceof Injectable) {
AndroidSupportInjection.inject(f);
}
}
}, true);
}
}
示例6: onItemClick
import android.support.v4.app.Fragment; //导入依赖的package包/类
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!ViewUtils.isFastDoubleClick() && this.activity != null) {
switch (parent.getId()) {
case R.id.lv_result:
Fragment addMaterialFragment = AddMaterialFragment.newInstance((
(FoodWithUnit) this.mResultAdapter.getItem(position)).code);
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.add(addMaterialFragment, "addMaterialFragment");
transaction.commitAllowingStateLoss();
return;
default:
return;
}
}
}
示例7: getTopFragment
import android.support.v4.app.Fragment; //导入依赖的package包/类
public static ISupportFragment getTopFragment(FragmentManager fragmentManager, int containerId) {
List<Fragment> fragmentList = FragmentationHack.getActiveFragments(fragmentManager);
if (fragmentList == null) return null;
for (int i = fragmentList.size() - 1; i >= 0; i--) {
Fragment fragment = fragmentList.get(i);
if (fragment instanceof ISupportFragment) {
ISupportFragment iFragment = (ISupportFragment) fragment;
if (containerId == 0) return iFragment;
if (containerId == iFragment.getSupportDelegate().mContainerId) {
return iFragment;
}
}
}
return null;
}
示例8: getItem
import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
* Returns a fragment for the current tab
* @param position
* @return a Fragment
*/
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch(position) {
case RADIO_FRAGMENT:
fragment = new RadioFragment();
break;
case SENSORS_FRAGMENT:
fragment = new SensorFragment();
break;
case TRACKING_FRAGMENT:
fragment = new TrackingFragment();
break;
}
return fragment;
}
示例9: onCreate
import android.support.v4.app.Fragment; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
if (fragment == null) {
fragment = createFragment();
fm.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
}
}
示例10: setBackgroundColor
import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
* 设置背景色
*
* @param fragment fragment
* @param color 背景色
*/
public static void setBackgroundColor(@NonNull Fragment fragment, @ColorInt int color) {
View view = fragment.getView();
if (view != null) {
view.setBackgroundColor(color);
}
}
示例11: setPrimaryItem
import android.support.v4.app.Fragment; //导入依赖的package包/类
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
mCurrentPrimaryItem.setMenuVisibility(false);
mCurrentPrimaryItem.setUserVisibleHint(false);
}
if (fragment != null) {
fragment.setMenuVisibility(true);
fragment.setUserVisibleHint(true);
}
mCurrentPrimaryItem = fragment;
}
}
示例12: refreshCurrentFragment
import android.support.v4.app.Fragment; //导入依赖的package包/类
public void refreshCurrentFragment(){
Fragment frag = getSupportFragmentManager().findFragmentById(R.id.fragment_main_container);
if(frag instanceof BookGridFragment){
((BookGridFragment) frag).refresh();
}else if(frag instanceof ViewPagerFragment){
((ViewPagerFragment) frag).refresh();
}
}
示例13: showFragmentByReplace
import android.support.v4.app.Fragment; //导入依赖的package包/类
private void showFragmentByReplace(Fragment fragment, boolean addToBackStack){
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (mCurrentFragment != null) {
fragmentTransaction.remove(mCurrentFragment);
mCurrentFragment = null;
}
if (addToBackStack) {
fragmentTransaction.addToBackStack(null);
}
fragmentTransaction.replace(R.id.content_container,fragment).commit();
mCurrentFragment = fragment;
}
示例14: initFragments
import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
* 初始化Fragments
*/
private void initFragments()
{
mHomePageFragment = HomePageFragment.newInstance();
// IFavoritesFragment mFavoritesFragment = IFavoritesFragment.newInstance();
// HistoryFragment mHistoryFragment = HistoryFragment.newInstance();
// AttentionPeopleFragment mAttentionPeopleFragment = AttentionPeopleFragment.newInstance();
// ConsumeHistoryFragment mConsumeHistoryFragment = ConsumeHistoryFragment.newInstance();
// SettingFragment mSettingFragment = SettingFragment.newInstance();
// fragments = new Fragment[]{
// mHomePageFragment,
// mFavoritesFragment,
// mHistoryFragment,
// mAttentionPeopleFragment,
// mConsumeHistoryFragment,
// mSettingFragment
// };
fragments = new Fragment[]{mHomePageFragment};
// 添加显示第一个fragment
getSupportFragmentManager()
.beginTransaction()
.add(R.id.container, mHomePageFragment)
.show(mHomePageFragment).commit();
}
示例15: showFragment
import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
* 显示fragment
*
* @param fragment fragment
* @return show的Fragment
*/
public static Fragment showFragment(@NonNull Fragment fragment) {
Args args = getArgs(fragment);
if (args != null) {
putArgs(fragment, new Args(args.id, false, args.isAddStack));
}
return operateFragment(fragment.getFragmentManager(), null, fragment, TYPE_SHOW_FRAGMENT);
}