Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:48:24+00:00 2026-06-14T08:48:24+00:00

In my android application, I have 3 Fragments.A,B,C.When I swipe like B->C->A , onViewCreated

  • 0

In my android application, I have 3 Fragments.A,B,C.When I swipe like B->C->A , onViewCreated method get called in fragment A so the application gets slow.I want to stop this onViewCreated getting called on page swipe. How can we make onViewCreated only get called at once when Mainactivity is created.Thanks in advance..

Main Activity=>

public class MainActivity extends FragmentActivity {

    private ViewPager mViewPager;

    private ProgressDialog pd;
    Button settings;
    static TextView flashnews;
    public static int stopflag=0;

    @Override
    public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Headlines.parse();


        SharedPreferences mlmprf = getSharedPreferences("malayalam", MODE_PRIVATE);
        final SharedPreferences.Editor mlmedit = mlmprf.edit();

        if(mlmprf.getBoolean("enable", true))
     {
         Headlines.headflag="malayalam";
     }
     else
     {
         Headlines.headflag="english";
     }





       flashnews=(TextView)findViewById(R.id.flashs);
       flashnews.setSelected(true);
       flashnews.setEllipsize(TruncateAt.MARQUEE);
       flashnews.setHorizontallyScrolling(true);
       flashnews.setSingleLine(true);
       flashnews.setLines(1);


        ;




                PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip);
        pagerTabStrip.setDrawFullUnderline(true);
        pagerTabStrip.setTabIndicatorColor(Color.rgb(174, 1, 34));



        // We get UI references
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mViewPager.setAdapter(new MyAdapter(this));
    }
 private class MyAdapter extends FragmentPagerAdapter{
 private Context mContext;
        private String[] frags = {A.class.getName(), B.class.getName(),C.class.getName()};

        public MyAdapter(FragmentActivity activity) {
            super(activity.getSupportFragmentManager());
            mContext = activity;
        }



        @Override
        public Fragment getItem(int pos) {
            return Fragment.instantiate(mContext, frags[pos]);
        }

        @Override
        public int getCount() {
            return frags.length;
        }

        @Override
        public CharSequence getPageTitle(int pos) {

            if(pos==0)
            return "A";

            if(pos==1)
            return "B";

            if(pos==2)
            return "C";

            else
            return null;


        }

    }
}

Fragment A=>

  public class A extends Fragment{


    public static String urls;
    // XML node keys
    static final String KEY_HEAD = "item"; // parent node
    //static final String KEY_TITLE = "title";
    static final String KEY_DATE = "pubDate";
    public static String headflag="english";
    public static String[] Title;
    public static String[] Description;
    public static String[] Tit;
    public static String[] Tit2;
    public static String[] Desc;
    public static String[] Desc2;
    public static String[] image;
    int f=0;
    GridView list;
    HeadlinesAdapter adapter;
    private TextView mMessageView;
    private Button mClearButton;
    public ArrayList<HashMap<String, String>> newsList; 


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflating layout
        View v = inflater.inflate(R.layout.headlines_fragment, container, false);
        // We obtain layout references

        return v;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // We set clear listener


        if(Headlines.headflag=="malayalam")
        {
            urls="http://www.abc.com/rssfeeds/19_18_17_25/1/rss.xml";


        }

        if(Headlines.headflag=="english")
        {
            urls="http://www.abc.com/en/rssfeeds/1_2_3_5/latest/rss.xml";


        }



        parse();
        populate_listview();    
    }


     public void populate_listview()
     {


        newsList = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(urls); // getting XML from URL
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_HEAD);
        // looping through all song nodes <song>
        NodeList itemLst = doc.getElementsByTagName("item");
        String MarqueeStr="";

        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);
            newsList.add(map);
            //MarqueeStr = MarqueeStr +" *** "+ Title[i];


     }

        list=(GridView)getActivity().findViewById(R.id.grid);

        // Getting adapter by passing xml data ArrayList
                 adapter=new HeadlinesAdapter(getActivity(), newsList);        
                 list.setAdapter(adapter);



    }

  public void parse()
     {

            URL url;

            try {

                url = new URL(urls);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                if((conn.getResponseCode() == HttpURLConnection.HTTP_OK)){
                      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                      DocumentBuilder db = dbf.newDocumentBuilder();
                      Document doc;
                      doc = db.parse(url.openStream());
                      doc.getDocumentElement().normalize();

                      NodeList itemLst = doc.getElementsByTagName("item");
                      Description = new String[itemLst.getLength()];//........
                      Title = new String[itemLst.getLength()];
                      Tit=new String[itemLst.getLength()];
                      Tit2=new String[itemLst.getLength()];
                      Desc=new String[itemLst.getLength()];
                      Desc2=new String[itemLst.getLength()];
                      image= new String[itemLst.getLength()];

                      for(int i=0; i < itemLst.getLength(); i++){

                            Node item = itemLst.item(i);
                            if(item.getNodeType() == Node.ELEMENT_NODE){
                                  Element ielem = (Element)item;
                                  NodeList title = ielem.getElementsByTagName("title");
                                  NodeList date = ielem.getElementsByTagName("pubDate");
                                  NodeList description = ielem.getElementsByTagName("description");
                                  Tit[i]= title.item(0).getChildNodes().item(0).getNodeValue();
                                  Desc[i]= description.item(0).getChildNodes().item(0).getNodeValue();
                                  Tit2[i]=Translate.title(Tit[i]);
                                  Desc2[i]=Translate.description(Desc[i]);
                                  if(Headlines.headflag=="malayalam")
                                    {
                                      Desc2[i]=Desc2[i].replace("read more","IqSpXÂ");
                                    }
                                  Title[i] =Tit2[i];
                                  if (Desc2[i].contains("<img ")){
                                      String img  = Desc2[i].substring(Desc2[i].indexOf("<img "));
                                      String cleanUp = img.substring(0, img.indexOf(">")+1);
                                      img = img.substring(img.indexOf("src=") + 5);
                                      int indexOf = img.indexOf("'");
                                      if (indexOf==-1){
                                          indexOf = img.indexOf("\"");
                                        }
                                      img = img.substring(0, indexOf);

                                //setImgLink(img);
                                    if(Headlines.headflag=="malayalam")
                                    {
                                        String img2=img.replace("files","files/imagecache/android_320");
                                        Description[i]=Desc2[i].replace(img,img2);
                                        image[i]=img2;
                                    }

                                else
                                {
                                    String img2=img.replace("files","files/imagecache/android_1_img");
                                    Description[i]=Desc2[i].replace(img,img2);
                                    image[i]=img2;
                                }
                                  }
                                else
                                {
                                    Description[i] =Desc2[i];
                                }



                            }

                          }

                        }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (DOMException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
     }





}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:48:25+00:00Added an answer on June 14, 2026 at 8:48 am

    I solved this myself by setting viewPager.setOffscreenPageLimit(3)…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a sample Fragment application. I have two fragments like list fragment
I would like to develop an Android application which will have a local database.
I'm developing an Android 3.1 tablet application and I have a Fragment ( android.support.v4.app.Fragment
I'm using fragments in my Android application using the compatibility package. I have tested
In my Android application, I have a fragment activity which it has a progressbar.
i made android application. In application i have web view where i want to
When creating an Android application using Loaders, should every activity and fragment have its
In my android application Iam using viewpager.I have two fragments.Fragment1 and Fragment2.Iam calling two
I am developing an application for Android 4.0.3. I have multiple fragments and I
I'm creating a tablet optimised application using fragments. I have a thin navigation fragment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.