Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get Application Context using SherlockFragmentActivity
    primarykey
    data
    text
    <p>My problem is similar to this question <a href="https://stackoverflow.com/questions/10854930/cant-make-static-reference-to-non-static-method-android-getapplicationcontext">Can&#39;t make static reference to non-static method ( Android getApplicationContext() )</a> I need to get the context of the SherlockFragmentActivity in order to access the database class. I tried the solution in this link above, but it did not work.</p> <p>Question 1: How do I get the context in the code below. </p> <p>Question 2: I get an error that forces me to use 'static' instead of public for the application context variable. I know that static is for a variable that does not change. However, this variable will change each time a tab is clicked on. Also, 'static' variables are not required for the database class. I'm confused as to why I need a static variable here. </p> <p>my SherlockFragmentActivity:</p> <pre><code>public class FragmentTabs extends SherlockFragmentActivity { TabHost mTabHost; TabManager mTabManager; static FragmentTabs appState; TabSwitchIdDatabase tsid = new TabSwitchIdDatabase(this); @Override protected void onCreate(Bundle savedInstanceState) { setTheme(SampleList.THEME); // Used for theme switching in samples super.onCreate(savedInstanceState); appState = ((FragmentTabs)getApplicationContext()); //.... more code } public static class TabManager implements TabHost.OnTabChangeListener {..// see code snipit below....} } </code></pre> <p>Where i need to put the context</p> <pre><code> public static class TabManager implements TabHost.OnTabChangeListener { //... more code static class DummyTabFactory implements TabHost.TabContentFactory { //... more code @Override public void onTabChanged(String tabId) { TabInfo newTab = mTabs.get(tabId); System.out.println(tabId); tsid.open();// broken , scoping problem Boolean x =tsid.tabExists(0); String tabIDfromDatabase = tsid.getTab(0);// broken , scoping problem tsid.close();// broken , scoping problem } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload