1

I am developing android app and app having action bar contain refresh button and overflow menu and below action bar having two stacked tab. when i click on refresh button individual tab will be refreshed for that task i want to call inner class from outer class using intent so i can refresh the inner class from server.

when i try to call inner class from outer class using intent i encountered exception like ActivityNotfound exception but i already mention inner class in manifest after solved . i tried lot of way but didn't worked.

following is the my class structure

public class Fragment extends SherlockFragmentActivity {
    ActionBar actionBar = getSupportActionBar();

    actionBar.setDisplayHomeAsUpEnabled(false);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Tab tab = actionBar.newTab().
            setText("Tab1").
            setTabListener(new Tab1())
            ;
    actionBar.addTab(tab);

    tab = actionBar.newTab().
            setText("Tab2").
            setTabListener(new Tab2())
            ;
    actionBar.addTab(tab);

    //I am tried number ways to refesh the particlar tab but not achieve my goal
    public void Refresh() {

        /* I am also write Refresh method on individual tab and call from 
        onOptionsItemSelected but not working*/

        Intent href = new Intent(Fragment.this,
                Tab1.class);  
        startActivity(href);
        finish();
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.menu_refresh:
            Refresh();
            return true;
        default:
            break;
        }
    }
    //inner class for tab first 
    public class Tab1 extends SherlockListFragment implements ActionBar.TabListener{

        // here implementating the TabListener method

        //here I am loading the list from server
        private class LoadProjects extends AsyncTask<String, String, String> {
            //call webservice
        }
    } 

    // inner class for tab second
    public class Tab2 extends SherlockListFragment implements ActionBar.TabListener{

        // here implementating the TabListener method

        //here I am loading the list from server

        private class LoadProjects extends AsyncTask<String, String, String> {
            //call webservice
        }
    } 
}

androidmanifest.xml

<application>
        <activity
            android:name="com.ojaswitech.bookingscape.Fragment"
            android:configChanges="orientation|keyboardHidden"
            android:label=""
            android:logo="@drawable/action_bar_logo"
            android:theme="@style/Theme.New_theme_bs" >
        </activity>
        <activity
            android:name="com.ojaswitech.bookingscape.Fragment$Tab1"
            android:configChanges="orientation|keyboardHidden" >
        </activity>
        <activity
            android:name="com.ojaswitech.bookingscape.Fragment$Tab2"
            android:configChanges="orientation|keyboardHidden" />
    </application>

Please anybody help me how to do above task. Thanks in advance

nilesh wani
  • 1,261
  • 5
  • 18
  • 30

3 Answers3

0

You should make Tab1 a public class in new file, Not inner class. That will solve the Refresh() method "Activity not found" Exception.

Ahmad Raza
  • 2,850
  • 1
  • 21
  • 37
  • I already have done similar work, if you need sample code then please let me know. – Ahmad Raza Jul 29 '13 at 07:16
  • I have post my complete code here. please check it.http://stackoverflow.com/questions/17918198/how-to-keep-tabs-visible-on-every-activity/17918804#17918804 Hope it will be helpful. – Ahmad Raza Jul 29 '13 at 08:03
0

Can I ask Why you want to use Intents here? I mean intents are abstraction/wrapper used to launch or communicate-with activities. Do read on Fragment concept to have a better idea on how fragments communicate with its host activity or vice-versa.

In this case you might need to implement an updateUI or refreshUI method in your child fragment. On clicking the refresh button, get your fragment(by id or instance) and call the child's update/refresh method.

See solution for How to refresh fragment tab content on button click

Happy coding!

Community
  • 1
  • 1
VenoM
  • 364
  • 3
  • 10
  • This might also help http://stackoverflow.com/questions/11578000/android-how-to-restart-refresh-a-fragment-from-fragmentactivty – VenoM Jul 29 '13 at 07:18
  • I don't understood from the first link is what should i write in refresh method(). – nilesh wani Jul 29 '13 at 07:59
  • Oh! Sorry. The first link is gives you a start to fragments, what-and-hows like basic stuff that you should know about it. Just out of curiosity are you experimenting with fragments like is this the first time that you are using a fragment in your app ? Depending on your answer i might be able to point you to a safe ground. – VenoM Jul 29 '13 at 08:37
  • Yes your correct and this is first time i am using fragment. thanks – nilesh wani Jul 29 '13 at 09:08
  • Ohk! Please read the fragment introduction(first link) that I added. As a dev you should be aware of that. Summary: Like Herrmann suggested Fragments need a host `Activity` to exist. Consider Fragment as a portion/section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running. – VenoM Jul 29 '13 at 09:51
  • From you code i assume that you are using `actionbarsherlock`. See https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock-samples/fragments/src/com/actionbarsherlock/sample/fragments/FragmentTabs.java – VenoM Jul 29 '13 at 09:52
0

you can refresh your fragment with the help of your_activity_context.recreate()

Sanket Shah
  • 4,352
  • 3
  • 21
  • 41