[ Šojka @ 30.06.2016. 12:12 ] @
Dobar dan, Imam jedan problem , kako prikazati Array u TextBox-u s praznim poljima ( tj. razmacima između brojeva)? Program generira random 6 brojeva od 1-49 i ispisuje ih u textbox pomoću tipke generate, sve radi ok al problem je što ne mogu razdvojiti brojeve u textboxu. Evo primjer koda: class MainActivity extends AppCompatActivity { private TextView txtView; private Button btnBingo; public void checkBingo (){ int []randomNumArray= new int [6]; randomNumArray [0] = randomNumber(); String numberString= ""; System.out.println(randomNumArray[0]); numberString+= randomNumArray[0]; txtView.setText(numberString); for (int i = 1; i<6; i++){ int candidate; boolean foundMatch; do { candidate = randomNumber(); foundMatch = false; for (int j=0; j<1; j++) if (candidate == randomNumArray[j]) foundMatch =true; }while (foundMatch); randomNumArray = candidate; System.out.println(randomNumArray); numberString +=randomNumArray; txtView.setText(numberString); } } public static int randomNumber () { return ( 1 + (int) (Math.random()*49)); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtView = (TextView)findViewById(R.id.txtView); btnBingo = (Button) findViewById(R.id.btnBingo); btnBingo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { checkBingo(); } }); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } |