when I run this programm the emulator only gives me one letter when random name is generated by clicking a button. I want to set the minimum generated lenghtname of chars in my string by 4 and maximum by 8. So the button generates a random Name by min 4 and max 8 letters from the String. Cant find any solution.
public class MainActivity extends AppCompatActivity {
private Switch Switch;
private EditText Name;
private Button btn;
private String items[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Switch = (Switch) findViewById(R.id.switch1);
Switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
openActivity2();
}
});
Name = findViewById(R.id.editTextTextPersonName);
btn = findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Random rndm = new Random();
int i = rndm.nextInt(items.length);
Name.setText(items [i]);
}
});
}
public void openActivity2() {
Intent intent = new Intent(this, MainActivity2.class);
startActivity(intent);
}
}
Thanks in advance.