J'ai reçu et les journaux de modèle dans l'application android. Réception hasMany journaux.
J'ai fait une requête pour group_by journaux par sortID et de qualité.
//recieve RecepitID and query to group logs
final long forwardedId = (long) getIntent().getExtras().get(String.valueOf("recepitID"));
List<Logs> logsList = new Select().from(Logs.class).where("Receipt = " + forwardedId).groupBy("SortID, Grade").execute();
Ce groupe fonctionne bien. Le problème est le suivant. J'ai besoin d'avoir sortie comme celle-ci (la partie dans le cercle rouge): mais j'ai comme ceci:
Et c'est une partie de code comment j'ai fait cela.
public class LogsRecapitulation extends AppCompatActivity {
private ListView mainListView;
private BaseAdapter listAdapter;
private TextView logsCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recapitulation_listview);
mainListView = (ListView) findViewById(R.id.ListViewItem);
//recieve RecepitID and query to group logs
final long forwardedId = (long) getIntent().getExtras().get(String.valueOf("recepitID"));
List<Logs> logsList = new Select().from(Logs.class).where("Receipt = " + forwardedId).groupBy("SortID, Grade").execute();
TextView result = (TextView) findViewById(R.id.LogMassResult);
double sum = 0.0;
for (int i = 0; i < logsList.size(); i++) {
sum += logsList.get(i).getM3();
}
result.setText(String.format("%.2f m3", sum));
for (int i = 0; i < logsList.size(); i++) {
if (logsList.get(i).receipt.priceType.equals("Na panju")) {
TextView stumpPriceKN = (TextView) findViewById(R.id.sumPriceKN);
double sumPricekn = 0.0;
for (int j = 0; j < logsList.size(); j++) {
sumPricekn += logsList.get(j).price.stumpPrice_kn * logsList.get(j).getM3();
}
stumpPriceKN.setText(String.format("%.2f KN", sumPricekn));
} else {
TextView roadKN = (TextView) findViewById(R.id.sumPriceKN);
double roadPrKn = 0.0;
for (int j = 0; j < logsList.size(); j++) {
roadPrKn += logsList.get(j).price.roadPrice_kn * logsList.get(j).getM3();
}
roadKN.setText(String.format("%.2f KN", roadPrKn));
}
}
for (int i = 0; i < logsList.size(); i++) {
if (logsList.get(i).receipt.priceCorrection > 0 && logsList.get(i).receipt.priceType.equals("Na panju")) {
TextView corecctionPriceKn = (TextView) findViewById(R.id.correctionPriceKN);
double correcSumKN = 0.0;
for (int j = 0; j < logsList.size(); j++) {
correcSumKN += (logsList.get(j).price.stumpPrice_kn * logsList.get(j).getM3()) + ((logsList.get(j).price.stumpPrice_kn * logsList.get(j).getM3()) * logsList.get(j).receipt.priceCorrection / 100);
}
corecctionPriceKn.setText(String.format("%.2f KN", correcSumKN));
} else if (logsList.get(i).receipt.priceCorrection > 0 && logsList.get(i).receipt.priceType.equals("Šumska cesta")) {
TextView corecctionPriceKn = (TextView) findViewById(R.id.correctionPriceKN);
double correcSumKN = 0.0;
for (int j = 0; j < logsList.size(); j++) {
correcSumKN += (logsList.get(j).price.roadPrice_kn * logsList.get(j).getM3()) + ((logsList.get(j).price.roadPrice_kn * logsList.get(j).getM3()) * logsList.get(j).receipt.priceCorrection / 100);
}
corecctionPriceKn.setText(String.format("%.2f KN", correcSumKN));
} else {
TextView priceHolder = (TextView) findViewById(R.id.KorekcijaCijene);
TextView corecctionPriceKn = (TextView) findViewById(R.id.correctionPriceKN);
priceHolder.setText("");
corecctionPriceKn.setText("");
}
}
listAdapter = new RecapitulationArrayAdapter(logsList);
mainListView.setAdapter(listAdapter);
//display logs count
logsCount = (TextView) findViewById(R.id.logsCount);
logsCount.setText(String.valueOf(logsList.size()));
}
private class RecapitulationArrayAdapter extends BaseAdapter {
private LayoutInflater inflater;
private List<Logs> logsList;
public RecapitulationArrayAdapter(List<Logs> logsList) {
inflater = LayoutInflater.from(LogsRecapitulation.this);
this.logsList = logsList;
}
@Override
public int getCount() {
return logsList.size();
}
@Override
public Object getItem(int position) {
return logsList.get(position);
}
@Override
public long getItemId(int position) {
return logsList.get(position).getId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.logs_recapitulation, parent, false);
}
Logs log = logsList.get(position);
((TextView) convertView.findViewById(R.id.rec_log_sort)).setText(log.sort_id);
((TextView) convertView.findViewById(R.id.rec_log_class)).setText(log.grade);
((TextView) convertView.findViewById(R.id.rec_log_count)).setText(String.valueOf(logsList.size()));
((TextView) convertView.findViewById(R.id.rec_logs_mass)).setText(String.format("%.2f m3", log.getM3()));
if (log.receipt.priceType.equals("Na panju")) {
((TextView) convertView.findViewById(R.id.rec_log_price_default)).setText(String.valueOf(log.price.stumpPrice_kn));
} else {
((TextView) convertView.findViewById(R.id.rec_log_price_default)).setText(String.valueOf(log.price.roadPrice_kn));
}
if (log.receipt.priceType.equals("Na panju")) {
((TextView) convertView.findViewById(R.id.rec_calculated_price)).setText(String.format("%.2f KN", log.price.stumpPrice_kn * log.getM3()));
} else {
((TextView) convertView.findViewById(R.id.rec_calculated_price)).setText(String.format("%.2f KN", log.price.roadPrice_kn * log.getM3()));
}
return convertView;
}
}
}
Je suis en utilisant ActiveAndroid et l'affichage de cette liste.
PROBLÈME avec l'affichage de ces éléments groupés. Je suis d'affichage dans BaseAdapter listView et il me montre un seul élément de chaque groupe, mais il doit me montrer plusieurs articles (car il a plus que 4 points dans chaque groupe).
Quelqu'un peut-il me donner des conseils que dois-je faire pour obtenir la sortie, comme sur la première image?