I am starting with Android studio and I have a problem I want to verify that when entering the name and surnames there are characters but to warn that you have not put anything.
The code is as follows:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class EAC1 extends AppCompatActivity {
TextView texto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eac1);
}
// Métodes dels botons!
public void ResetTextNom (View vista){ //Hem creat aquest métode que el que fa es que al donar a la X esborri la info.
TextView TexToResultado = (TextView) findViewById(R.id.TextNom); //fem la variable TextoResultado es canvia per textNom
TexToResultado.setText(""); // cambia el text actual a un " "
}
// Ahora vamos hacer el TEXTVIEW.
public void TextAcceptat (View vista){
texto = (TextView) findViewById(R.id.TextNom); // Primer verifiquem el text i l'agafem
if(texto ==null){ // Verifiquem que no estigui buït
Toast toast1 = Toast.makeText(getApplicationContext(),"Heu d'escriure quelcom!",Toast.LENGTH_LONG);
toast1.show();
}else{
Toast toast2 = Toast.makeText(getApplicationContext(),"bien!",Toast.LENGTH_SHORT);
toast2.show();
}
}}
I have the problem in the final part of the if text = null ...
attachment layout ..
<EditText
android:id="@+id/TextNom"
android:text="@string/name"
android:layout_width="295dp"
android:layout_height="49dp"
android:layout_marginBottom="321dp"
android:ems="10"
android:inputType="textAutoComplete|textPersonName"
android:textColor="@color/colorNegre"
android:textColorLink="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="MissingConstraints,RtlHardcoded"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_co
Could it be that I'm missing something in the layout? In the buttons you have to create the android: onclick .. but I do not know if in the texts too ..
thanks!