lundi 27 juin 2016

Dont repeat after shown (Random)

I have a button when its pressed it shows a random text. I have another button thats when pressed it will remove the case so it wont be displayed again. How to do that? Here is my code :

    public class TasksActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_tasks);

    final Button tasksbtn = (Button)findViewById(R.id.btnfortasks);
    Button removeCase = (Button)findViewById(R.id.remove_case); 


    tasksbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Random taskRandom = new Random();
            TextView tasksView = (TextView)findViewById(R.id.tasks_textView);
            switch (taskRandom.nextInt() %4) {
                case 0:
                    tasksView.setText("one");
                    break;
                case 1:
                    tasksView.setText("two");
                    break;
                case 2:
                    tasksView.setText("three");
                    break;
                case 3:
                    tasksView.setText("four");
                    break;
                default:
                    break;
            }

        }
    });




Aucun commentaire:

Enregistrer un commentaire