Good evening, I'm creating an app that generates random numbers for me, but I had an idea that makes it easier for the user .... When he wants to generate more than one block of random numbers, he chooses the amount he wants and sends generate, and shows the blocks of numbers generated according to what the user chose ....
With Gambiarra you can do: I create several textview and adapt with the switch ... but I wanted to do something right ...
I created a generate method that instantiates the class with the function of generating random numbers, and within seekbar I put a switch to do this action according to the amount that the user chose ... more wanted to show inside a listview. Can you do that? Can someone help me?
code:
package com.nathan.lotogera.lotogera.Fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.nathan.lotogera.lotogera.Controller.NumberRandom;
import com.nathan.lotogera.lotogera.R;
import java.util.ArrayList;
import java.util.Random;
public class DuplaSena extends Fragment {
private TextView group1, alert, group2, quantJogos;
public Button calculate;
public SeekBar jogos;
private ListView lista;
public DuplaSena() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_dupla_sena, container, false);
group1 = (TextView) view.findViewById(R.id.textView1);
alert = (TextView) view.findViewById(R.id.textView2);
group2 = (TextView) view.findViewById(R.id.textView3);
quantJogos = (TextView) view.findViewById(R.id.textjogoShow);
jogos = (SeekBar) view.findViewById(R.id.seekJogos);
lista = (ListView) view.findViewById(R.id.listateste);
calculate = (Button) view.findViewById(R.id.button1);
String[] teste = new String[0];
final ArrayAdapter<String> listagem = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
teste
);
lista.setAdapter(listagem);
jogos.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (progress){
case 1:
gera();
break;
case 2:
gera();
break;
}
quantJogos.setText("reste " + progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(getActivity(), "parou", Toast.LENGTH_SHORT).show();
}
});
return view;
}
public void gera(){
NumberRandom numberRandom = new NumberRandom();
numberRandom.megaSena();
String groupFirst = numberRandom.getPrimary();
String groupSecond = numberRandom.getSecond();
}
}