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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:44:00+00:00 2026-05-12T17:44:00+00:00

I have an activity that extends ExpandableListActivity. I use SimpleCursorTreeAdapter to fill ExpandableListView. My

  • 0

I have an activity that extends ExpandableListActivity. I use SimpleCursorTreeAdapter to fill ExpandableListView.
My layout contains list view and empty view.
On app start ExpandableListActivity automatically chooses the right view to display.

My steps:

  1. App starts, there is no data. (empty view on the screen)
  2. Insert some data into db.
  3. Call adapter.notifyDataSetChanged(); But empty view is still on the screen and there is no any item in my list view.

Then I restart app:

  1. List view appears. I expand all groups and scroll to the bottom.
  2. I click on the item in the list. New activity appears.
  3. Click back button. All groups are collapsed and we are at the top of the screen. Scroll position and expanded groups are not remembered.
  4. Delete all data from db and call adapter.notifyDataSetChanged();
  5. Child views have disappeared, but top-level groups are still visible.

Questions:

  1. What can I do to replace empty view with list view?
  2. What can I do to do to save state of groups and scroll position of the list view?

Tested on SDKs: 1.5r3, 1.6r1

Code:

public class MainActivity extends ExpandableListActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        dbHelper = new DBOpenHelper(this);

        rubricsDbAdapter = new RubricsDBAdapter(dbHelper);
        rubricsDbAdapter.open();

        itemsDbAdapter = new ItemsDBAdapter(dbHelper);
        itemsDbAdapter.open();

        rubricsCursor = rubricsDbAdapter.getAllItemsCursor();
        startManagingCursor(rubricsCursor);

        // Cache the ID column index
        rubricIdColumnIndex = rubricsCursor.getColumnIndexOrThrow(RubricsDBAdapter.KEY_ID);

        // Set up our adapter
        mAdapter = new MyExpandableListAdapter(rubricsCursor,
                this,
                android.R.layout.simple_expandable_list_item_1,
                android.R.layout.simple_expandable_list_item_1,
                new String[] {RubricsDBAdapter.KEY_NAME},
                new int[] {android.R.id.text1},
                new String[] {ItemsDBAdapter.KEY_NAME}, 
                new int[] {android.R.id.text1});

        setListAdapter(mAdapter);
    }

    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        Intent i = new Intent(this, ItemViewActivity.class);
        i.putExtra(ItemsDBAdapter.KEY_ID, id);
        startActivity(i);

        return super.onChildClick(parent, v, groupPosition, childPosition, id);
    }

    private void updateMyData() {
        int i;
        int k;
        long rubricId;

        for (i = 1; i <= 5; i++) {
            rubricId = rubricsDbAdapter.insert("rubric " + i);
            for (k = 1; k <= 5; k++) {
                itemsDbAdapter.insert("item " + i + "-" + k, rubricId);
            }
        }

        mAdapter.notifyDataSetChanged();
    }

    private void deleteMyData() {
        rubricsDbAdapter.deleteAll();
        itemsDbAdapter.deleteAll();

        mAdapter.notifyDataSetChanged();
    }

    public class MyExpandableListAdapter extends SimpleCursorTreeAdapter 
    {
        public MyExpandableListAdapter(Cursor cursor, Context context, int groupLayout,
                int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
                int[] childrenTo) {
            super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom,
                    childrenTo);
        }

        @Override
        protected Cursor getChildrenCursor(Cursor notebookCursor) {
            // Given the group, we return a cursor for all the children within that group 
            long id = notebookCursor.getLong(rubricIdColumnIndex);

            Cursor itemsCursor = itemsDbAdapter.getRubricItemsCursor(id);
            startManagingCursor(itemsCursor);
            return itemsCursor;
        }

    }
}
  • 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-05-12T17:44:01+00:00Added an answer on May 12, 2026 at 5:44 pm

    So, the answer is:

    1. Call cursor.requery() before calling adapter’s notifyDataSetChanged() method.
    2. Save groups state in activity’s onPause() method and restore in onResume() method.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an class that extends ExpandableListActivity. To fill the data for this list,
I have an activity that extends ListView. I populate my list with the results
I have a class that extends Activity and inflates another xml layout in the
I have following goal: From a list in main activity that extends ListActivity, I
I have an activity that uses ExpandableListActivity but now I want it to use
I have an activity that extends ViewFactory. The activity does nothing more than act
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity that extends MapActivity, and inside onCreate() I have this code
I have a jar that consists of a class that extends Activity and performs
I have an Android activity that displays a list of log entries (using a

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.