Advertisement
Ankhwatcher

tableCreator

Aug 28th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1.     TableLayout tableCreator(List<String[]> list, int noOfColumns) {
  2.         TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
  3.  
  4.         TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f);
  5.  
  6.         TableLayout tableLayout = new TableLayout(getActivity());
  7.  
  8.         tableLayout.setLayoutParams(tableParams);
  9.         TableRow tableRow = new TableRow(getActivity());
  10.         for (int i = 0; i < list.size(); i++) {
  11.  
  12.  
  13.             View view = getView(list.get(i));
  14.             view.setLayoutParams(rowParams);
  15.  
  16.             tableRow.addView(view);
  17.  
  18.             if (noOfColumns==1 || i % noOfColumns == 1 || i == list.size()-1) {
  19.                 tableRow.setLayoutParams(tableParams);
  20.                 tableRow.setWeightSum(1f*noOfColumns);
  21.                 tableLayout.addView(tableRow);
  22.                 tableRow = new TableRow(getActivity());
  23.  
  24.             }
  25.         }
  26.         return tableLayout;
  27.     }
  28.  
  29.     public View getView(String string[]) {
  30.  
  31.         LayoutInflater inflater = getActivity().getLayoutInflater();
  32.  
  33.         View view = inflater.inflate(R.layout.panel_result_list, null);
  34.  
  35.         TextView name = (TextView) view.findViewById(R.id.name);
  36.         TextView value = (TextView) view.findViewById(R.id.value);
  37.         name.setText(string[0]);
  38.         value.setText(formatDate(string[1]));
  39.  
  40.         return view;
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement