Android - Problema con el método setText

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 14 puestos en Android (en relación al último mes)
Gráfica de Android

Problema con el método setText

Publicado por Nico (1 intervención) el 18/01/2019 12:22:25
Hola tengo un problema al intentar modificar el valor de un textView con el método setText y no se porque. Lo modifico al principio y al final pero hago una modificación en medio que no me la ejecuta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import static java.lang.Thread.sleep;
 
public class MainActivity extends AppCompatActivity {
 
    Button iniciar;
    Button pausa;
    Button reiniciar;
    EditText editText;
    TextView textView;
    int segundos = 0;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        iniciar = (Button)findViewById(R.id.iniciar);
        pausa = (Button)findViewById(R.id.pausa);
        reiniciar = (Button)findViewById(R.id.reiniciar);
        editText = (EditText)findViewById(R.id.editText);
        textView = (TextView)findViewById(R.id.textView);
        textView.setText(String.valueOf(segundos));
 
        iniciar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                if (entero(editText.getText().toString())){
                    segundos = Integer.parseInt(editText.getText().toString());
                    textView.setText(String.valueOf(segundos));
                    Toast.makeText(getApplicationContext(), "pasa por aquí" , Toast.LENGTH_LONG).show();
                    textView.setText("antes");
                    try {
                        textView.setText("try");
                        sleep(segundos*1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    textView.setText("Fin");
                    Toast.makeText(getApplicationContext(), "mensaje2" , Toast.LENGTH_LONG).show();
                }else {
                   Toast.makeText(getApplicationContext(), "El número insertado no es válido" , Toast.LENGTH_LONG).show();
 
                }
            }
        });
        pausa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
            }
        });
 
        reiniciar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.setText("");
            }
        });
    }
 
    public void pasardatos(){
        textView.setText(String.valueOf(segundos));
    }
    private void runThread(){
        new Thread(){
            public void run(){
                do {
 
                }while (segundos>=0);
            }
        }.start();
    }
 
    public boolean entero(String valorEdittext){
        boolean comprobacion = false;
        try {
            Integer.parseInt(valorEdittext);
            comprobacion = true;
        }catch (Exception e){
            comprobacion = false;
        }
        return comprobacion;
    }
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder