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 8435329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:53:06+00:00 2026-06-10T06:53:06+00:00

Here is the situation. i am currently using a list fragment in one of

  • 0

Here is the situation.

i am currently using a list fragment in one of my tabs using action bar. have 3 tabs; tab1, tab2, tab3.. listfragment is on tab2 and just some Fragment on tab1, so when i start my app defualt is ont tab1.. and when i click on tab2 it loads something from the database, TAKE NOTE HAVE ONLY ONE ROW CURRENTLY STORED IN DATABASE so when i click back on tab1 den after clicked again on tab2 suddenly my list has already two items of the same values, it just got duplicated or loaded twice.. and i have only 1 entry on my database.

how do i prevent my fragment to load the list twice, i mean when i load this listfragment the second time around it will just load what is on the db and removes that previous value on listFragment. my theory on this problem is that, the first time i clicked tab2 its ok, when i click tab1 den after tab2, the previous items weren’t deleted and when the fragment is loaded it is appended to the previous item..

how do i prevent this from happening..

enter image description here

Here is a sample picture, don’t mind the UI flaws but just imagine that entry got doubled from loading the fragment twice.

This is a snippet on onActivityCreated

public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        loadPatientList(0);
    }

This is my loadPatientList()

Cursor c = dbHelper.retrieveAllData(PATIENT_TABLE);
c.moveToFirst();       
while(!c.isAfterLast())
{
    Patients p = new Patients();
    Log.d("patient id",Integer.toString(c.getInt(c.getColumnIndex("_id"))));
    p.setId(c.getString(c.getColumnIndex("_id")));
    p.setFname(c.getString(c.getColumnIndex("firstname")));
    p.setMi(c.getString(c.getColumnIndex("middlename")));
    p.setLname(c.getString(c.getColumnIndex("lastname")));
    p.setAddr(c.getString(c.getColumnIndex("address")));
    p.setHosp_name(c.getString(c.getColumnIndex("hosp_name")));
    p.setHosp_room(c.getString(c.getColumnIndex("hosp_room")));
    p.setAge(c.getInt(c.getColumnIndex("age")));
    p.setMed_history(c.getString(c.getColumnIndex("med_history")));
    p.setPat_status(c.getInt(c.getColumnIndex("status")));
    patient_list.add(p);

    c.moveToNext();
}

dbHelper.close();

Collections.sort(patient_list, new Comparator<Patients>() {
   public int compare(Patients o1, Patients o2) {
      return o1.getLname().compareToIgnoreCase(o2.getLname());
   }
});

PatientAdapter patientListAdapter = new PatientAdapter(getActivity(),R.layout.patient_list_item_fragment, patient_list);
setListAdapter(patientListAdapter);
registerForContextMenu(getListView());
  • 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-10T06:53:07+00:00Added an answer on June 10, 2026 at 6:53 am
    onActivityCreated()
    

    is called when you resume the “PatientFragment“. Since List, allows duplicate, everytime you go back to “PatientFragment“, you fill up patient_list again and again. Just before enter the while cycle, try to clear your patient_list, removing all the elements (List should be have the clear() method).

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

Sidebar

Related Questions

Ok, so here's the situation. I currently have a view controller called MainViewController which
Here's my current situation: I have a NSMutableArray named dictKeyArray which I assign a
Here is my current situation; I am a near complete regexp illiterate, and have
Not even sure I'm stating the question correctly. Here's the situation. I have a
I have an situation here that looks very like a SELECT N+1 from the
I have a strange situation here. In my android app, I have a layout
I have a simple situation here. lets face html code first => <form name=geoKey
Here is my situation, I have a string as follows 'a':1 'b':2 'c':3 I
Here's my situation: using PHP and MySQL as my backend, jQuery and jsTree for
So here is the situation. I have a database on a remote server that

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.