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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:02+00:00 2026-05-23T15:20:02+00:00

Yayy, coding is so much fun. This is my third attempt at creating an

  • 0

Yayy, coding is so much fun. This is my third attempt at creating an ExpandableListView that is linked to a sqllite db. The last version worked ok when retrieving data, but not so great when I needed to delete or edit an item. It was based off of the Api Demo, expandableListView 1 and 2. The Api code suggested that I store my info in an array before it could be put into a ExpandablelistView. I think we can all see an issue with deleting and updating items that are stored in an array. I decided to start over, with something much cleaner.

The following code is my attempt at creating an activity that fills an expandableListView with sqllite db values. However, nothing happens when the activity starts, not even an exception.

I assume that my problem lies within browseView.setAdapter(mAdapter); but I really don’t know what Im’m talking about and have no way to prove it! If I change the above to a listadapter it throws a nullpointerexception.

Lastly, it should be noted that my getChildren cursor passes my groupCursor straight though. This is only because I haven’t figured out what goes in here! Babysteps.

Am I on the right track here? Thanks for taking a look.

public class BrowseActivity extends ExpandableListActivity {

final private String[] asColumnsToReturn = {
    Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_ITEM,
    Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_DESC,
    Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_ID };

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse);
DbHelper dbh = new DbHelper(this.getApplicationContext());
SQLiteDatabase db = dbh.getWritableDatabase();
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(Items.ITEMS_TABLE_NAME);
ExpandableListView browseView = (ExpandableListView)findViewById(android.R.id.list);

Cursor mCursor = queryBuilder.query(db, asColumnsToReturn, null, null,
        null, null, Items.DEFAULT_SORT_ORDER);
startManagingCursor(mCursor);


SimpleCursorTreeAdapter mAdapter = new SimpleCursorTreeAdapter(this,
        mCursor, R.layout.row, R.layout.exprow,
        new String[] { Items.ITEMS_ITEM }, new int[] { R.id.txtItem },
        R.layout.exprow, R.layout.exprow, new String[] { Items.ITEMS_DESC },
        new int[] { R.id.dscItem }) {

    @Override
    protected Cursor getChildrenCursor(Cursor groupCursor) {


        return groupCursor;
    }
};

browseView.setAdapter(mAdapter);


}

}

***START NEW OF NEW CLASS FILE***

public class DbHelper extends SQLiteOpenHelper  {


private static final int DATABASE_VERSION = 1;
private static final String DB_NAME = "itemList.db";



DbHelper(Context context) {

super(context, DB_NAME, null, DATABASE_VERSION);

}   

@Override
public void onCreate(SQLiteDatabase db){

db.execSQL("CREATE TABLE " + Items.ITEMS_TABLE_NAME + " (" 
   + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," 
   + Items.ITEMS_ITEM + " TEXT," + Items.ITEMS_DESC + " TEXT," 
   + Items.ITEMS_MANU + " TEXT," + Items.ITEMS_UPC + " TEXT," +
   Items.ITEMS_NWEIGHT + " TEXT," + Items.ITEMS_AWEIGHT + " TEXT)");

}

 @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
@Override
public void onOpen(SQLiteDatabase db){
super.onOpen(db);
}
}

***START OF NEW CLASS FILE***
public class ItemDatabase {

private ItemDatabase() {
}

public static final class Items implements BaseColumns {

private Items() {
}

public static final String ITEMS_TABLE_NAME = "table_itemList";
public static final String ITEMS_ID = "_id";
public static final String ITEMS_ITEM = "item";
public static final String ITEMS_DESC = "description";
public static final String ITEMS_MANU = "manufacturer";
public static final String ITEMS_UPC = "upc";
public static final String ITEMS_NWEIGHT = "netweight";
public static final String ITEMS_AWEIGHT = "actualweight";
public static final String DEFAULT_SORT_ORDER = "item ASC";
}

And the “browse” xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">

<ExpandableListView 
android:id = "@android:id/list" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"
android:clickable="true"
></ExpandableListView>

</LinearLayout>
  • 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-23T15:20:03+00:00Added an answer on May 23, 2026 at 3:20 pm

    Its because I passed the Group cursor straight through the getChildrenCursor() method. You have to create a new Cursor inside the method.

    @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) {
    
            String tempGroup = groupCursor.getString(groupCursor
                    .getColumnIndex(Items.ITEMS_ITEM));
    
            DbHelper dbh = new DbHelper(BrowseActivity.this);
            SQLiteDatabase db = dbh.getWritableDatabase();
    
            String sqlString = "SELECT " + Items.ITEMS_ID + ", "
                    + Items.ITEMS_DESC + ", " + Items.ITEMS_MANU + ", "
                    + Items.ITEMS_NWEIGHT + ", " + Items.ITEMS_AWEIGHT + ", "
                    + Items.ITEMS_UPC + " FROM " + Items.ITEMS_TABLE_NAME
                    + " WHERE " + Items.ITEMS_ITEM + "=" + "'" + tempGroup
                    + "'";
            Cursor mCursor = db.rawQuery(sqlString, null);
    
            return mCursor;
    
        }
    

    And the Row Layout file:

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView 
    android:layout_gravity="center_vertical|right" 
    android:id="@+id/txtItem" 
    android:text="Item" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:textSize="15dip"
    
    ></TextView>
    
    
    <TextView 
    android:layout_gravity="center_vertical|right" 
    android:id="@+id/dscItemTwo" 
    android:text="Desciption" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:textStyle="italic"
    android:textColor="#666666"
    
    ></TextView>
    
    </LinearLayout>
    

    Finally the expRow Layout(It’s a little long, I have alot of table rows. I must admit things are poorly named too. I just wanted to get it working before I made it pretty!):

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_span = "2"
    android:stretchColumns="0"
    
    >
    <TableRow 
    android:layout_height="wrap_content" 
    android:id="@+id/tableRow1" 
    android:layout_gravity="right" 
    android:layout_width="wrap_content"
    >
        <TableRow 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"
        android:layout_weight = "1" 
        android:id="@+id/tableRow10"
        android:layout_gravity="right"
        >
            <TextView 
            android:layout_marginRight="1dip" 
            android:textColor="#994020" 
            android:layout_height="wrap_content" 
            android:layout_gravity="right" 
            android:layout_width="wrap_content" 
            android:text="Manufacturer" 
            android:id="@+id/manuItem"
            ></TextView>
    
        </TableRow>
    
        <TableRow 
        android:layout_height="wrap_content" 
        android:id="@+id/tableRow11" 
        android:layout_width="wrap_content"
        ></TableRow>
    
       </TableRow>
        <TableRow 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:id="@+id/tableRow2"
        >
            <TableRow 
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:id="@+id/tableRow9"
            android:layout_gravity="right"
            android:layout_weight="1"
    
    
            >
    
                <TextView 
                android:layout_marginRight="1dip"
                android:textColor="#994020" 
                android:layout_height="wrap_content" 
                android:layout_gravity="right" 
                android:layout_width="wrap_content" 
                android:text="Description" 
                android:id="@+id/dscItem"
                ></TextView>
            </TableRow>
    
            <TableRow 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:id="@+id/tableRow8"
            ></TableRow>
    
         </TableRow>
    
            <TableRow 
            android:layout_height="wrap_content" 
            android:id="@+id/tableRow3" 
            android:layout_width="fill_parent"
    
    
            >
                <TableRow 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/tableRow6" 
    
                android:layout_gravity="right" 
                android:baselineAligned="true">
                    <TextView
                     android:layout_marginRight="1dip"
                     android:textColor="#994020" 
                     android:layout_height="wrap_content" 
                     android:layout_gravity="right" 
                     android:text="Net Weight" 
                     android:id="@+id/nWeightItem" 
                     android:layout_width="wrap_content"
    
    
                      ></TextView>
                </TableRow>
                <TableRow 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/tableRow7" 
    
    
                >
                    <TextView 
                    android:layout_marginRight="1dip"
                    android:layout_gravity="right"
                    android:layout_height="wrap_content" 
                    android:layout_width="wrap_content" 
                    android:text="ounces" 
                    android:textStyle="italic"
                    android:id="@+id/textView1" 
    
                    ></TextView>
                </TableRow>
            </TableRow>
            <TableRow
             android:layout_height="wrap_content" 
             android:id="@+id/tableRow5" 
             android:layout_width="wrap_content"
             >
                <TableRow 
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent" 
                android:id="@+id/tableRow12"
                android:layout_weight="1"
                android:layout_gravity="right"
                >
                    <TextView 
                    android:layout_marginRight="1dip" 
                    android:textColor="#994020" 
                    android:layout_height="wrap_content" 
                    android:layout_gravity="right" 
                    android:layout_width="wrap_content" 
                    android:text="Actual Weight" 
                    android:id="@+id/aWeightItem"
                    ></TextView>
                </TableRow>
                <TableRow 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/tableRow13"
                >
                <TextView
                    android:layout_marginRight="1dip"
                    android:layout_gravity="right"
                    android:layout_height="wrap_content" 
                    android:layout_width="wrap_content" 
                    android:text="ounces" 
                    android:textStyle="italic"
                    android:id="@+id/textView111" 
                    ></TextView>
                </TableRow>
    
            </TableRow>
    
            <TableRow 
            android:id="@+id/tableRow4" 
            android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             >
                <TableRow 
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_gravity="right" 
                android:id="@+id/tableRow14"
                >
                    <TextView 
                    android:layout_marginRight="1dip" 
                    android:textColor="#994020" 
                    android:layout_height="wrap_content" 
                    android:layout_gravity="right" 
                    android:layout_width="wrap_content" 
                    android:text="UPC" 
                    android:id="@+id/upcItem"
                    ></TextView>
                </TableRow>
                <TableRow 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/tableRow15"
                ></TableRow>
            </TableRow>
    
    
     </TableLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP5 DOMDocument and I try to find the root node (not

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.