Good afternoon, I'm trying to loop my random numbers .... I have two spinner, 1 with a choice of how many random numbers and the other how many times have to appear in a ListView ...
My problem is that it generates the amount of random numbers, but not the amount of times. I wanted to know how to do it .... Well I can not do it.
Code:
package com.nathan.lotogera.lotogera.Fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.nathan.lotogera.lotogera.Controller.MegaSenaController;
import com.nathan.lotogera.lotogera.R;
import java.util.ArrayList;
import java.util.List;
public class DuplaSena extends Fragment {
private TextView groupText, quantJogos;
private Button calculate;
private SeekBar jogos;
private ListView lista;
private Spinner spinner, teste;
String [] valuesRound =
{"Quantidade de Nº","6", "7"};
String [] multiplicar =
{"Teste","1","2", "3"};
public DuplaSena() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_dupla_sena, container, false);
groupText = (TextView) view.findViewById(R.id.txtResult);
lista = (ListView) view.findViewById(R.id.listateste);
spinner = (Spinner) view.findViewById(R.id.spinnerNumber);
teste = (Spinner) view.findViewById(R.id.teste);
calculate = (Button) view.findViewById(R.id.btnMostrar);
groupText.setVisibility(View.INVISIBLE);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, valuesRound);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 1:
geraSix();
break;
case 2:
geraSeven();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(getActivity(), "Nenhum item selecionado!", Toast.LENGTH_LONG).show();
}
});
calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
groupText.setVisibility(View.VISIBLE);
}
});
ArrayAdapter<String> adapters = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, multiplicar);
adapters.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
teste.setAdapter(adapters);
teste.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 1:
int qant = teste.getSelectedItemPosition();
for(int a = 0; a>=qant; a++){
geraSix();
}
break;
case 2:
int qz = teste.getSelectedItemPosition();
for(int a = 1; a<=qz; a++){
geraSix();
}
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(getActivity(), "Nenhum item selecionado!", Toast.LENGTH_LONG).show();
}
});
return view;
}
public void geraSix(){
List<String> teste = new ArrayList<>();
final ArrayAdapter<String> listagem = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
teste
);
lista.setAdapter(listagem);
MegaSenaController numberRandom = new MegaSenaController();
numberRandom.megaSena();
String groupFirst = numberRandom.getPrimary();
listagem.add(groupFirst);
}
}
Can anyone help me? Thank you ...