本文整理匯總了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);
}