0

런타임에 항목을 만들고 싶습니다. 설정하고 싶은 FragmentActivity에 전역 변수가 있으며 onActivityCreated() 메서드의 단편에서이 변수를 사용합니다. 그러나 분명히 그들은 그들이 생성 될 때 null이며, 단편이 생성 될 때까지 데이터를 사용해야 할 필요가 없습니다. 누구든지이 일을하는 좋은 방법을 찾았습니까? 나는 현재 이것을하기 위해 ActionBarSherlock을 사용하고있다.ActionBarSherlock을 사용하여 활동을 만든 후 조각을 새로 고치는 방법

Fragment는 새로 고칠 수 있지만 Activity는 새로 고침 할 수 없으면 모든 항목이 다시 null이됩니다.

제발 아무도 도와 줄 수 없어요. 미리 감사드립니다.

FragmentActivity 코드 :

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!"); 
    } 

} 

} 

답변

관련 문제