Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 10.48 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ExpandableListView does not appear when Activity starts
  2. public class BrowseActivity extends ExpandableListActivity {
  3.  
  4. final private String[] asColumnsToReturn = {
  5.     Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_ITEM,
  6.     Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_DESC,
  7.     Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_ID };
  8.  
  9. @Override
  10. public void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.browse);
  13. DbHelper dbh = new DbHelper(this.getApplicationContext());
  14. SQLiteDatabase db = dbh.getWritableDatabase();
  15. SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
  16. queryBuilder.setTables(Items.ITEMS_TABLE_NAME);
  17. ExpandableListView browseView = (ExpandableListView)findViewById(android.R.id.list);
  18.  
  19. Cursor mCursor = queryBuilder.query(db, asColumnsToReturn, null, null,
  20.         null, null, Items.DEFAULT_SORT_ORDER);
  21. startManagingCursor(mCursor);
  22.  
  23.  
  24. SimpleCursorTreeAdapter mAdapter = new SimpleCursorTreeAdapter(this,
  25.         mCursor, R.layout.row, R.layout.exprow,
  26.         new String[] { Items.ITEMS_ITEM }, new int[] { R.id.txtItem },
  27.         R.layout.exprow, R.layout.exprow, new String[] { Items.ITEMS_DESC },
  28.         new int[] { R.id.dscItem }) {
  29.  
  30.     @Override
  31.     protected Cursor getChildrenCursor(Cursor groupCursor) {
  32.  
  33.  
  34.         return groupCursor;
  35.     }
  36. };
  37.  
  38. browseView.setAdapter(mAdapter);
  39.  
  40.  
  41. }
  42.  
  43. }
  44.  
  45. ***START NEW OF NEW CLASS FILE***
  46.  
  47. public class DbHelper extends SQLiteOpenHelper  {
  48.  
  49.  
  50. private static final int DATABASE_VERSION = 1;
  51. private static final String DB_NAME = "itemList.db";
  52.  
  53.  
  54.  
  55. DbHelper(Context context) {
  56.  
  57. super(context, DB_NAME, null, DATABASE_VERSION);
  58.  
  59. }  
  60.  
  61. @Override
  62. public void onCreate(SQLiteDatabase db){
  63.  
  64. db.execSQL("CREATE TABLE " + Items.ITEMS_TABLE_NAME + " ("
  65.    + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
  66.    + Items.ITEMS_ITEM + " TEXT," + Items.ITEMS_DESC + " TEXT,"
  67.    + Items.ITEMS_MANU + " TEXT," + Items.ITEMS_UPC + " TEXT," +
  68.    Items.ITEMS_NWEIGHT + " TEXT," + Items.ITEMS_AWEIGHT + " TEXT)");
  69.  
  70. }
  71.  
  72.  @Override
  73. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  74.  
  75. }
  76. @Override
  77. public void onOpen(SQLiteDatabase db){
  78. super.onOpen(db);
  79. }
  80. }
  81.  
  82. ***START OF NEW CLASS FILE***
  83. public class ItemDatabase {
  84.  
  85. private ItemDatabase() {
  86. }
  87.  
  88. public static final class Items implements BaseColumns {
  89.  
  90. private Items() {
  91. }
  92.  
  93. public static final String ITEMS_TABLE_NAME = "table_itemList";
  94. public static final String ITEMS_ID = "_id";
  95. public static final String ITEMS_ITEM = "item";
  96. public static final String ITEMS_DESC = "description";
  97. public static final String ITEMS_MANU = "manufacturer";
  98. public static final String ITEMS_UPC = "upc";
  99. public static final String ITEMS_NWEIGHT = "netweight";
  100. public static final String ITEMS_AWEIGHT = "actualweight";
  101. public static final String DEFAULT_SORT_ORDER = "item ASC";
  102. }
  103.        
  104. <?xml version="1.0" encoding="utf-8"?>
  105. <LinearLayout
  106.  
  107. xmlns:android="http://schemas.android.com/apk/res/android"
  108. android:layout_width="fill_parent"
  109. android:layout_height="fill_parent" android:orientation="vertical">
  110.  
  111. <ExpandableListView
  112. android:id = "@android:id/list"
  113. android:layout_height="fill_parent"
  114. android:layout_width="fill_parent"
  115. android:clickable="true"
  116. ></ExpandableListView>
  117.  
  118. </LinearLayout>
  119.        
  120. @Override
  121.     protected Cursor getChildrenCursor(Cursor groupCursor) {
  122.  
  123.         String tempGroup = groupCursor.getString(groupCursor
  124.                 .getColumnIndex(Items.ITEMS_ITEM));
  125.  
  126.         DbHelper dbh = new DbHelper(BrowseActivity.this);
  127.         SQLiteDatabase db = dbh.getWritableDatabase();
  128.  
  129.         String sqlString = "SELECT " + Items.ITEMS_ID + ", "
  130.                 + Items.ITEMS_DESC + ", " + Items.ITEMS_MANU + ", "
  131.                 + Items.ITEMS_NWEIGHT + ", " + Items.ITEMS_AWEIGHT + ", "
  132.                 + Items.ITEMS_UPC + " FROM " + Items.ITEMS_TABLE_NAME
  133.                 + " WHERE " + Items.ITEMS_ITEM + "=" + "'" + tempGroup
  134.                 + "'";
  135.         Cursor mCursor = db.rawQuery(sqlString, null);
  136.  
  137.         return mCursor;
  138.  
  139.     }
  140.        
  141. <?xml version="1.0" encoding="utf-8"?>
  142.  
  143. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  144. android:id="@+id/LinearLayout1"
  145. android:layout_width="fill_parent"
  146. android:layout_height="fill_parent"
  147. android:orientation="vertical">
  148. <TextView
  149. android:layout_gravity="center_vertical|right"
  150. android:id="@+id/txtItem"
  151. android:text="Item"
  152. android:layout_height="wrap_content"
  153. android:layout_width="fill_parent"
  154. android:textSize="15dip"
  155.  
  156. ></TextView>
  157.  
  158.  
  159. <TextView
  160. android:layout_gravity="center_vertical|right"
  161. android:id="@+id/dscItemTwo"
  162. android:text="Desciption"
  163. android:layout_height="wrap_content"
  164. android:layout_width="fill_parent"
  165. android:textStyle="italic"
  166. android:textColor="#666666"
  167.  
  168. ></TextView>
  169.  
  170. </LinearLayout>
  171.        
  172. <?xml version="1.0" encoding="utf-8"?>
  173. <TableLayout
  174.  xmlns:android="http://schemas.android.com/apk/res/android"
  175. android:layout_width="fill_parent"
  176. android:layout_height="fill_parent"
  177. android:layout_span = "2"
  178. android:stretchColumns="0"
  179.  
  180. >
  181. <TableRow
  182. android:layout_height="wrap_content"
  183. android:id="@+id/tableRow1"
  184. android:layout_gravity="right"
  185. android:layout_width="wrap_content"
  186. >
  187.     <TableRow
  188.     android:layout_height="wrap_content"
  189.     android:layout_width="fill_parent"
  190.     android:layout_weight = "1"
  191.     android:id="@+id/tableRow10"
  192.     android:layout_gravity="right"
  193.     >
  194.         <TextView
  195.         android:layout_marginRight="1dip"
  196.         android:textColor="#994020"
  197.         android:layout_height="wrap_content"
  198.         android:layout_gravity="right"
  199.         android:layout_width="wrap_content"
  200.         android:text="Manufacturer"
  201.         android:id="@+id/manuItem"
  202.         ></TextView>
  203.  
  204.     </TableRow>
  205.  
  206.     <TableRow
  207.     android:layout_height="wrap_content"
  208.     android:id="@+id/tableRow11"
  209.     android:layout_width="wrap_content"
  210.     ></TableRow>
  211.  
  212.    </TableRow>
  213.     <TableRow
  214.     android:layout_height="wrap_content"
  215.     android:layout_width="fill_parent"
  216.     android:id="@+id/tableRow2"
  217.     >
  218.         <TableRow
  219.         android:layout_height="wrap_content"
  220.         android:layout_width="fill_parent"
  221.         android:id="@+id/tableRow9"
  222.         android:layout_gravity="right"
  223.         android:layout_weight="1"
  224.  
  225.  
  226.         >
  227.  
  228.             <TextView
  229.             android:layout_marginRight="1dip"
  230.             android:textColor="#994020"
  231.             android:layout_height="wrap_content"
  232.             android:layout_gravity="right"
  233.             android:layout_width="wrap_content"
  234.             android:text="Description"
  235.             android:id="@+id/dscItem"
  236.             ></TextView>
  237.         </TableRow>
  238.  
  239.         <TableRow
  240.         android:layout_height="wrap_content"
  241.         android:layout_width="wrap_content"
  242.         android:id="@+id/tableRow8"
  243.         ></TableRow>
  244.  
  245.      </TableRow>
  246.  
  247.         <TableRow
  248.         android:layout_height="wrap_content"
  249.         android:id="@+id/tableRow3"
  250.         android:layout_width="fill_parent"
  251.  
  252.  
  253.         >
  254.             <TableRow
  255.             android:layout_height="wrap_content"
  256.             android:layout_width="wrap_content"
  257.             android:id="@+id/tableRow6"
  258.  
  259.             android:layout_gravity="right"
  260.             android:baselineAligned="true">
  261.                 <TextView
  262.                  android:layout_marginRight="1dip"
  263.                  android:textColor="#994020"
  264.                  android:layout_height="wrap_content"
  265.                  android:layout_gravity="right"
  266.                  android:text="Net Weight"
  267.                  android:id="@+id/nWeightItem"
  268.                  android:layout_width="wrap_content"
  269.  
  270.  
  271.                   ></TextView>
  272.             </TableRow>
  273.             <TableRow
  274.             android:layout_height="wrap_content"
  275.             android:layout_width="wrap_content"
  276.             android:id="@+id/tableRow7"
  277.  
  278.  
  279.             >
  280.                 <TextView
  281.                 android:layout_marginRight="1dip"
  282.                 android:layout_gravity="right"
  283.                 android:layout_height="wrap_content"
  284.                 android:layout_width="wrap_content"
  285.                 android:text="ounces"
  286.                 android:textStyle="italic"
  287.                 android:id="@+id/textView1"
  288.  
  289.                 ></TextView>
  290.             </TableRow>
  291.         </TableRow>
  292.         <TableRow
  293.          android:layout_height="wrap_content"
  294.          android:id="@+id/tableRow5"
  295.          android:layout_width="wrap_content"
  296.          >
  297.             <TableRow
  298.             android:layout_height="wrap_content"
  299.             android:layout_width="fill_parent"
  300.             android:id="@+id/tableRow12"
  301.             android:layout_weight="1"
  302.             android:layout_gravity="right"
  303.             >
  304.                 <TextView
  305.                 android:layout_marginRight="1dip"
  306.                 android:textColor="#994020"
  307.                 android:layout_height="wrap_content"
  308.                 android:layout_gravity="right"
  309.                 android:layout_width="wrap_content"
  310.                 android:text="Actual Weight"
  311.                 android:id="@+id/aWeightItem"
  312.                 ></TextView>
  313.             </TableRow>
  314.             <TableRow
  315.             android:layout_height="wrap_content"
  316.             android:layout_width="wrap_content"
  317.             android:id="@+id/tableRow13"
  318.             >
  319.             <TextView
  320.                 android:layout_marginRight="1dip"
  321.                 android:layout_gravity="right"
  322.                 android:layout_height="wrap_content"
  323.                 android:layout_width="wrap_content"
  324.                 android:text="ounces"
  325.                 android:textStyle="italic"
  326.                 android:id="@+id/textView111"
  327.                 ></TextView>
  328.             </TableRow>
  329.  
  330.         </TableRow>
  331.  
  332.         <TableRow
  333.         android:id="@+id/tableRow4"
  334.         android:layout_width="wrap_content"
  335.          android:layout_height="wrap_content"
  336.          >
  337.             <TableRow
  338.             android:layout_height="wrap_content"
  339.             android:layout_width="fill_parent"
  340.             android:layout_weight="1"
  341.             android:layout_gravity="right"
  342.             android:id="@+id/tableRow14"
  343.             >
  344.                 <TextView
  345.                 android:layout_marginRight="1dip"
  346.                 android:textColor="#994020"
  347.                 android:layout_height="wrap_content"
  348.                 android:layout_gravity="right"
  349.                 android:layout_width="wrap_content"
  350.                 android:text="UPC"
  351.                 android:id="@+id/upcItem"
  352.                 ></TextView>
  353.             </TableRow>
  354.             <TableRow
  355.             android:layout_height="wrap_content"
  356.             android:layout_width="wrap_content"
  357.             android:id="@+id/tableRow15"
  358.             ></TableRow>
  359.         </TableRow>
  360.  
  361.  
  362.  </TableLayout>