In my activity, there are two buttons: one for adding an item to a ListView, which is formed by an EditText (where the user enters a decimal number) and another one, which will start the calculation. The goal is to calculate the average of the numbers entered in the EditTexts, depending on the number of items added to the ListView.
I have the following code, and I think I might get the number of childs created and then divide the adding by the childs, but I have read a lot of similar examples and I have no idea how to do that.
Here is the code:
void addNumberFromText()
{
double total=0;
for(int i=0;i<MarkListView.getChildCount();i++)
{
View wantedView = MarkListView.getChildAt(i);
markresult = (TextView)wantedView.findViewById(R.id.subjectmark);
double value=Double.parseDouble(markresult.getText().toString());
total+=value;
}
markresult1 = (TextView)findViewById(R.id.average);
markresult1.setText(Double.toString(total));
markresult1.setText(String.format("%.2f", total));
}
I appreciate the help, thank you!
See Question&Answers more detail:os