Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to split the numbers in android .split();
    text
    copied!<p>i have problem with splitting text/numbers method, i want to split the numbers of the Text Edit line and i have this code does i'm doing the wrong way ? Here is my whole code:</p> <pre><code> package com.trafika.rafa; import java.util.Scanner; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button calculate = (Button) findViewById(R.id.calculateB); final TextView RM = (TextView) findViewById(R.id.returnMoney1); final EditText GM = (EditText) findViewById(R.id.gMoney); final EditText COP = (EditText) findViewById(R.id.cOP); calculate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { int givedMoney = Integer.parseInt(GM.getText().toString()); // String returnMoney = RM.getText().toString(); // String CostOfProduct = COP.getText().toString(); int CostOfProduct = Integer.parseInt(COP.getText().toString()); String parts[] = COP.getText().toString().split(" "); for (int i = 0; i &lt; parts.length; i++) { CostOfProduct += Integer.parseInt(parts[i]); } int returnmoney; returnmoney = givedMoney - CostOfProduct; if (givedMoney &lt; CostOfProduct) { returnmoney = CostOfProduct - givedMoney; RM.setTextColor(Color.RED); RM.setText("Need more " + returnmoney + " den"); return; } RM.setTextColor(Color.WHITE); RM.setText(returnmoney + " den"); } catch (Exception e) { e.printStackTrace(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>and now when ill run the application doesn't calculate good the numbers its confused </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload