Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. public void updateLastExpenses(){
  2. Cursor c = Expense.getAll(this);
  3.  
  4. TableLayout lastExpensesTable = (TableLayout)findViewById(R.id.lastExpensesTable);
  5.  
  6. lastExpensesTable.setStretchAllColumns(true);
  7.  
  8. while (c.moveToNext()) {
  9.  
  10.  
  11. android.text.format.DateFormat df = new android.text.format.DateFormat();
  12.  
  13. String name = c.getString(
  14. c.getColumnIndexOrThrow(ExpenseContract.ExpenseEntry.COLUMN_NAME_NAME)
  15. );
  16. float amount = c.getFloat(
  17. c.getColumnIndexOrThrow(ExpenseContract.ExpenseEntry.COLUMN_NAME_AMOUNT)
  18. );
  19.  
  20. String date = c.getString(
  21. c.getColumnIndexOrThrow(ExpenseContract.ExpenseEntry.COLUMN_NAME_DATE)
  22. );
  23.  
  24. TableRow tr = new TableRow(this);
  25.  
  26. TextView c1 = new TextView(this);
  27. c1.setText(name);
  28. c1.setBackgroundColor(Color.RED);
  29.  
  30. TextView c2 = new TextView(this);
  31. c2.setText(""+amount);
  32. c2.setBackgroundColor(Color.BLUE);
  33.  
  34.  
  35. tr.addView(c1);
  36. tr.addView(c2);
  37.  
  38. lastExpensesTable.addView(tr);
  39.  
  40. }
  41.  
  42. }
  43.  
  44. <TableLayout
  45. android:layout_width="match_parent"
  46. android:layout_height="wrap_content"
  47. android:id="@+id/lastExpensesTable">
  48. <TableRow
  49. android:id="@+id/lastExpensesTableRow"
  50. android:layout_width="match_parent"
  51. android:layout_height="wrap_content">
  52. <TextView
  53. android:id="@+id/lastExpensesTableName"
  54. android:text="@string/last_expenses_table_name"/>
  55. <TextView />
  56. <TextView
  57. android:id="@+id/lastExpensesTableAmount"
  58. android:text="@string/last_expenses_table_amount"/>
  59. <TextView />
  60. </TableRow>
  61. </TableLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement