public void addTableBody(TableLayout table) { Cursor cursor = mySQLiteHelper.executeQuery(this.buildTableQuery()); int row = 0; if (cursor != null && cursor.moveToFirst()) { do { TableRow tr = new TableRow(getActivity()); tr.setGravity(Gravity.CENTER); for (int i = 0; i < columnNames.length; i++) { String value = cursor.getString(cursor.getColumnIndex(columnNames[i])); TextView tv = getCellTextView(value, row); tr.addView(tv); } table.addView(tr); Long id = cursor.getLong(cursor.getColumnIndex("_id")); tr.setTag(id); tr.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Long id = Long.valueOf(v.getTag().toString()); String xml = formBuilder.buildFormSubmissionXMLString(form, id); ((FormDataActivity) getActivity()).switchToDisplayFormFragment(1, xml); } }); row++; } while (cursor.moveToNext()); } }
@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { layoutInflater = inflater; View view = inflater.inflate(R.layout.preview_data_fragment, container, false); ButterKnife.bind(this, view); formBuilder = FormBuilder.getInstance(getActivity()); swipeRefreshLayout.setOnRefreshListener(this); mySQLiteHelper = MySQLiteHelper.getInstance(getActivity()); columnNames = mySQLiteHelper.getColumnNamesForTable(form.getTableName()); // TableRow rowTitle = getTableTitleView(); TableRow tableHeaders = getColumnHeaders(); // tableLayout.addView(rowTitle); tableLayout.addView(tableHeaders); addTableBody(tableLayout); return view; }