У меня есть две таблицы в базе данных.Объединив оба, я получаю новый стол.Теперь я хочу показать значения этой таблицы на странице PDF, но она показывает только одну строку.Как я могу показать все значения таблиц в PdfTable.Я использую библиотеку iText здесь.Метод базы данных здесь:
public List<PSummaryModel> testMethodSummary(){
String ps = "Not Found";
SQLiteDatabase db = this.getWritableDatabase();
String query = "select p_name, sum(i_amount) i_amount, sum(e_amount) e_amount, sum(i_amount)-sum(e_amount) profit " +
"from (" +
"select sr, date, project_id, expense_id expense_id, 0 i_amount, e_amount e_amount, description " +
"from expense_voucher" +
" union all " +
"select sr, date, project_id, income_id income_id, i_amount i_amount, 0 e_amount, description " +
"from income_voucher) v, projects p " +
"where v.project_id=p.p_id " +
"group by p_name ";
Cursor cursor = db.rawQuery(query, null);
List<PSummaryModel> summaryModelList = new ArrayList<>();
while (cursor.moveToNext()){
PSummaryModel pSummaryModel = new PSummaryModel(cursor.getString(0), cursor.getLong(1), cursor.getLong(2), cursor.getLong(3));
summaryModelList.add(pSummaryModel);
}
return summaryModelList;
}
вот код таблицы pdf:
listOfSummaryModel = databaseHelper.testMethodSummary();
for (PSummaryModel pSummaryModel : listOfSummaryModel) {
PdfPCell cell = null;
cell = new PdfPCell(Phrase.getInstance(pSummaryModel.getP_title()));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
tables.addCell(cell);
cell = new PdfPCell(Phrase.getInstance(String.valueOf(pSummaryModel.getTotalIncome())));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
tables.addCell(cell);
cell = new PdfPCell(Phrase.getInstance(String.valueOf(pSummaryModel.getTotalExpense())));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
tables.addCell(cell);
cell = new PdfPCell(Phrase.getInstance(String.valueOf(pSummaryModel.getProfit())));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
tables.addCell(cell);
document.add(tables);
document.close();
}