I need help to sum all the integers in the arrayList and view the result of the sum in the text view, all the eight number is from edit text here is the full code that get the integer from edit text and view the sum result on the text view
public class MainActivity extends AppCompatActivity {
EditText editText;
Button button;
TextView textView;
int one, two, three, four, five, six, seven, eight;
int Result;
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
textView = (TextView) findViewById(R.id.text);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String data = editText.getText().toString();
one = Integer.parseInt(data.charAt(0) + "");
two = Integer.parseInt(data.charAt(1) + "");
three = Integer.parseInt(data.charAt(2) + "");
four = Integer.parseInt(data.charAt(3) + "");
five = Integer.parseInt(data.charAt(4) + "");
six = Integer.parseInt(data.charAt(5) + "");
seven = Integer.parseInt(data.charAt(6) + "");
eight = Integer.parseInt(data.charAt(7) + "");
int[] mNumber = {one, two * 2, three, four * 2, five, six * 2, seven, eight * 2};
for (int n : mNumber) {
spiltInt(n);
}
}
});
}
public void spiltInt(int x) {
String number = String.valueOf(x);
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < number.length(); i++) {
int j = Character.digit(number.charAt(i), 10);
list.add(j);
}
}
}