Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在使用ActionBarSherlock创建活动后刷新片段_Android_Android Fragments_Actionbarsherlock_Android Fragmentactivity - Fatal编程技术网

Android 如何在使用ActionBarSherlock创建活动后刷新片段

Android 如何在使用ActionBarSherlock创建活动后刷新片段,android,android-fragments,actionbarsherlock,android-fragmentactivity,Android,Android Fragments,Actionbarsherlock,Android Fragmentactivity,我想在运行时创建一些东西,我想在FragmentActivity中设置全局变量,然后由onActivityCreated方法中的片段使用它们。但是很明显,当它们被创建时是空的,直到片段被创建之后,我才需要使用数据。有没有人想出一个好办法?我目前正在使用ActionBarSherlock来执行此操作 我希望能够刷新片段,但不能刷新活动,因为那样所有内容都将再次为空 请任何人帮我做这个。先谢谢你 碎片活动代码: public class SlidingTabsActivity extends She

我想在运行时创建一些东西,我想在FragmentActivity中设置全局变量,然后由onActivityCreated方法中的片段使用它们。但是很明显,当它们被创建时是空的,直到片段被创建之后,我才需要使用数据。有没有人想出一个好办法?我目前正在使用ActionBarSherlock来执行此操作

我希望能够刷新片段,但不能刷新活动,因为那样所有内容都将再次为空

请任何人帮我做这个。先谢谢你

碎片活动代码:

public class SlidingTabsActivity extends SherlockFragmentActivity
{   

/* Sliding tabs */
private ViewPager viewPager;
private TabsAdapter tabsAdapter;
private ActionBar actionBarTabs;

/* Custom tab view */
private LayoutInflater customTabViewLayoutInflater;
private View customTabView;

/* Layer interfaces */
private CommsLayerInterface commsLayerInterface;
private DeviceLayerInterface deviceLayerInterface;

private PopupFirmware popupFirmware; // Popup firmware class instance

/* Data set information */
private DeviceInfo deviceInfo;
private Pages pages;
private Page page1;
private Page page2;
private Page page3;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    viewPager = new ViewPager(this);
    viewPager.setId(R.id.pager);
    setContentView(viewPager);

    tabsAdapter = new TabsAdapter(this, viewPager); // Declares the tabs adapter class with the view pager view

    popupFirmware = new PopupFirmware(this); // Declaring popup firmware class

    commsLayerInterface = new CommsLayerInterface();
    deviceLayerInterface = new DeviceLayerInterface(this);

    deviceLayerInterface.setCommsLayerInterface(commsLayerInterface);

    /* Custom tab view instances */
    customTabViewLayoutInflater = (LayoutInflater) this.getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    customTabView = customTabViewLayoutInflater.inflate(R.layout.tabs_spinner, null);

    /* Custom view functions */
    TabCustomViewFunctions.createSpinnerList(this, customTabView, deviceLayerInterface);
    TabCustomViewFunctions.createNewFile(this, customTabView, deviceLayerInterface);
    TabCustomViewFunctions.saveFile(customTabView, deviceLayerInterface);

    /* Set up pages and device info */
    deviceInfo = deviceLayerInterface.getDeviceInfo();
    pages = deviceLayerInterface.getPages();
    setUpPages(pages);

    /* Action Bar */
    actionBarTabs = getSupportActionBar();
    actionBarTabs.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBarTabs.setCustomView(customTabView);
    actionBarTabs.setDisplayShowCustomEnabled(true);    

    /* Adds fragments to the tabs adapter */
    tabsAdapter.addTab(actionBarTabs.newTab().setText("FRAG1"), Fragment_1.class, null);
    tabsAdapter.addTab(actionBarTabs.newTab().setText("FRAG2"), Fragment_2.class, null);
    tabsAdapter.addTab(actionBarTabs.newTab().setText("FRAG3"), Fragment_3.class, null);

}
}
片段代码:

public class Fragment_1 extends SherlockFragment
{
private View view;
private CustomLayout layout; // Container view layout class instance
private SlidingTabsActivity slidingTabsActivity;
private DeviceInfo deviceInfo;
private Page page;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    view = inflater.inflate(R.layout.fragment_custom, container, false);

    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) 
{
    super.onActivityCreated(savedInstanceState); 

    /* Creates the new views from the layout class */
    slidingTabsActivity = (SlidingTabsActivity) getSherlockActivity();
    deviceInfo = slidingTabsActivity.getDeviceInfo();
    page = slidingTabsActivity.getPage1(); 

    if(page != null & deviceInfo != null)
    {
        layout = new CustomLayout(slidingTabsActivity);
        layout.setDeviceInfo(deviceInfo);
        layout.setPage(page);
        layout.createView();

        System.out.println("Page and device info are NOT null!");
    }
    else
    {
        System.out.println("Page and device info are null!");
    }

}

}

使用接口使用活动回调。回调用于刷新片段

此链接将帮助您