Edit Text Drawable Icon ändern plus Funktion

wer112

Top Contributor
Ich möchte mich in Sachen Style weiterbilden und habe ein YT Video nachprogrammiert. Wo ein Simples Login Fenster gemacht wurden ist.
Im Edit Text bei Email ist ein Pfeil und beim Passwort ist ein Auge.

Ich möchte wenn ich das Auge drücke, dass Icon Ausgewechselt wird und das Passwort wieder als Text angezeigt wird und umgekehrt.
Wenn die Email adresse Stimmt, soll der Pfeil Grün werden.

ein setDrawableClickListener gibt es nicht, laut SOF gibt es den(irgendwo stand das)

Wie greife ich auf das Symbol zu, ändere die Funktion und tausche es aus?

Möchte keine Übertriebende riesige Lösung haben.

Gib es was kleines?

Java:
<EditText
                android:id="@+id/email_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:drawableEnd="@drawable/done_icon"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="Password"
                android:alpha="0.7"
                android:textStyle="bold"/>

            <EditText
                android:id="@+id/password_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:drawableEnd="@drawable/password_icon"
                />

Danke im Vorraus.
 

Jw456

Top Contributor
ein setDrawableClickListener gibt es nicht, laut SOF gibt es den(irgendwo stand das)
Wozu auch? Mit was agierst du oder der User doch wohl mit dem (Auge) und Text (Tastatur)


Auf das Auge (ImgaeView) kannst du einen setzen.
Auf die den EditText kannst du zb. den addTextChangedListener (TextWatcher) setzen somit hast du alles was du brauchst.
 
Zuletzt bearbeitet:

wer112

Top Contributor
Wozu auch? Mit was agierst du oder der User doch wohl mit dem (Auge) und Text (Tastatur)


Auf das Auge (ImgaeView) kannst du einen setzen.
Das Auge ist ja im EditText drinnen und kein eigenes ImageView. Kann man trotzdem über die ID darauf zugreifen?
Auf die den EditText kannst du zb. den addTextChangedListener (TextWatcher) setzen somit hast du alles was du brauchst.
Und das ist dafür, das man das Passwort anzeigen lassen kann? Also z.B. imageView.addTextChangedListener("Text");
oder wie läuft es denn ab?
 

wer112

Top Contributor
Ich habe das mit dem Input Sache gemacht, da klappt das mit dem Passwort anzeigen. Leider KP wieso man das nicht anders machen kann. Gibt es auch sowas ähnliches, wo man den Done Pfeil ändern kann, wenn man Sachen reinschreibt?
 

Marinek

Bekanntes Mitglied
Ja, das gibt es... Am besten, wenn man selbst implementiert.

Listener an die entsprechende Komponente, die dann die Zielkomponente entsprechend den Wünschen ändert.
 

wer112

Top Contributor
zeige doch mal das ganze Layout

Ursprünglich:

XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bitcoin_hintergrund"
    tools:context=".Login">

    <TextView
        android:id="@+id/login_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="70dp"
        android:text="Bitcoin Earn"
        android:textStyle="bold"
        android:textSize="40sp"
        android:textColor="#562AA5"/>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:cardCornerRadius="28dp"
        android:layout_marginBottom="-20dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="20dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Login"
                android:textColor="#562AA5"
                android:textSize="32sp"
                android:textStyle="bold"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Please login with your information"
                android:alpha="0.7"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:text="Email Address"
                android:alpha="0.7"
                android:textStyle="bold"/>


            <EditText
                android:id="@+id/email_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:drawableEnd="@drawable/done_icon"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="Password"
                android:alpha="0.7"
                android:textStyle="bold"/>

            <EditText
                android:id="@+id/password_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:drawableEnd="@drawable/password_icon"
                />
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Remember me"
                    android:layout_centerVertical="true"
                    android:alpha="0.7"/>

                <TextView
                    android:id="@+id/forgot_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="I forgot my password"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"/>
            </RelativeLayout>

            <Button
                android:id="@+id/login_btn"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="30dp"
                android:layout_marginBottom="10dp"
                android:text="Login"
                android:textStyle="bold"
                android:textColor="#ffffff"
                android:textSize="20sp"
                android:background="@drawable/login_btn"/>

            <TextView
                android:id="@+id/register_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="I need an account"
                android:alpha="0.7"
                android:layout_marginTop="15dp"
                android:layout_marginBottom="15dp"
                android:layout_gravity="center_horizontal"/>
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</RelativeLayout>


Habe es mit den TextFields probiert:

XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bitcoin_hintergrund"
    tools:context=".Login">

    <TextView
        android:id="@+id/login_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="70dp"
        android:text="Bitcoin Earn"
        android:textStyle="bold"
        android:textSize="40sp"
        android:textColor="#562AA5"/>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:cardCornerRadius="28dp"
        android:layout_marginBottom="-20dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="20dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Login"
                android:textColor="#562AA5"
                android:textSize="32sp"
                android:textStyle="bold"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Please login with your information"
                android:alpha="0.7"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:text="Email Address"
                android:alpha="0.7"
                android:textStyle="bold"/>


            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:endIconDrawable="@drawable/done_icon"
                android:id="@+id/email_input"
                app:endIconMode="custom">
                <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/email_login"
                    />
            </com.google.android.material.textfield.TextInputLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Password"
                android:layout_marginTop="15dp"
                android:textStyle="bold"
                android:alpha="0.7"/>

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:endIconMode="password_toggle">
                <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/password_login"
                    android:inputType="textPassword"/>

            </com.google.android.material.textfield.TextInputLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Remember me"
                    android:layout_centerVertical="true"
                    android:alpha="0.7"/>

                <TextView
                    android:id="@+id/forgot_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="I forgot my password"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"/>
            </RelativeLayout>

            <Button
                android:id="@+id/login_btn"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="30dp"
                android:layout_marginBottom="10dp"
                android:text="Login"
                android:textStyle="bold"
                android:textColor="#ffffff"
                android:textSize="20sp"
                android:background="@drawable/login_btn"/>

            <TextView
                android:id="@+id/register_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="I need an account"
                android:alpha="0.7"
                android:layout_marginTop="15dp"
                android:layout_marginBottom="15dp"
                android:layout_gravity="center_horizontal"/>
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</RelativeLayout>

Habe dann das in Java probiert mit den TextFields:

Java:
package ;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.Patterns;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.textfield.TextInputLayout;

public class Login extends AppCompatActivity {

    TextView forgot, register;
    EditText email_edit, password_edit;

    TextInputLayout email;

    Button login_btn;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        email_edit = (EditText)findViewById(R.id.email_login);
        password_edit = (EditText) findViewById(R.id.password_login);

        email = (TextInputLayout)findViewById(R.id.email_input);

        login_btn = (Button)findViewById(R.id.login_btn);
        login_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginPrüfung();
            }
        });





        register = (TextView)findViewById(R.id.register_login);

        forgot = (TextView) findViewById(R.id.forgot_password);

        forgot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Login.this, Reset_Passwort.class));
            }
        });

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Login.this, Registration.class));
            }
        });



    }

    private void LoginPrüfung(){
        String emailadresse = email_edit.getText().toString().trim();
        String password = password_edit.getText().toString().trim();

        Boolean all_right = true;

        if (emailadresse.isEmpty()){
            email_edit.setError("Email is Empty");
            email_edit.requestFocus();

            all_right = false;

        }else if (!Patterns.EMAIL_ADDRESS.matcher(emailadresse).matches()){
            email_edit.setError("Email is not right");
            email_edit.requestFocus();
            all_right = false;
        }

        if (password.isEmpty()){
            password_edit.setError("Password is Empty");
            password_edit.requestFocus();
            all_right = false;

        }

        if (all_right){
            email.setEndIconDrawable(AppCompatResources.getDrawable(this, R.drawable.true_done));
        }

    }

    @Override
    public void onBackPressed() {
        Log.e("BackPressed", "Reset Password");
    }
}
 

wer112

Top Contributor
Ich benutze jetzt ein ImageView.

Habe das Problem grade, das das grüne Done nur weggeht, wenn Email leer ist. Aber es soll auch ausgehen, wenn die Email Adresse nicht gültig ist. Bleibt aber an:

Java:
if (emailadresse.isEmpty()){
            email_edit.setError("Email is Empty");
            email_edit.requestFocus();
            done.setImageDrawable(getResources().getDrawable(R.drawable.done_icon));


            all_right = false;

        }else if (!Patterns.EMAIL_ADDRESS.matcher(emailadresse).matches()){
            email_edit.setError("Email is not right");
            email_edit.requestFocus();
            done.setImageDrawable(getResources().getDrawable(R.drawable.done_icon));

            all_right = false;
        }
 

Jw456

Top Contributor
Dann denke über deine Auswahl Logik deimer if nach.

Du solltest villeicht auf beide Bedingungen zusammen prüfen.

In deiner if Struktur ist ja nach zwei Bedingungen Schluß du hast aber drei.
 

wer112

Top Contributor
Dann denke über deine Auswahl Logik deimer if nach.

Du solltest villeicht auf beide Bedingungen zusammen prüfen.

In deiner if Struktur ist ja nach zwei Bedingungen Schluß du hast aber drei.

Das habe ich auch.
Also wenn email adresse nicht leer ist, dann kommt ein grüner Pfeil.
Wenn es aber leer ist oder Falsch ist, soll der graue Pfeil kommen.
Grün wird es, aber nicht mehr zurück, wenn man auf den Button drückt.

Java:
if(!emailadresse.isEmpty()){
            done.setImageDrawable(getResources().getDrawable(R.drawable.true_done));

        }
 

Jw456

Top Contributor
Du hast es doch mit Worten doch schon richtig formuliert.
Also wenn eine Bedingung war ist und die zweite auch dann soll etwas geschehen (grün ) sonst nicht (grau)

So nun schreibe das auch in Java.
 

wer112

Top Contributor
Du hast es doch mit Worten doch schon richtig formuliert.
Also wenn eine Bedingung war ist und die zweite auch dann soll etwas geschehen (grün ) sonst nicht (grau)

So nun schreibe das auch in Java.
Ich habe 3 Bedingungen. Ist Email leer = frauer Feil. Ist Email Falsch dann grauer Pfeil.
Ist die Email Richtig, dann Grüner Pfeil. Wir in allen 3 BEdingungen geprüft.

GEht trotzdem nicht.
 

Jw456

Top Contributor
Das habe ich auch.
Also wenn email adresse nicht leer ist, dann kommt ein grüner Pfeil.
Wenn es aber leer ist oder Falsch ist, soll der graue Pfeil kommen.
Grün wird es, aber nicht mehr zurück, wenn man auf den Button drückt.

Java:
if(!emailadresse.isEmpty()){
            done.setImageDrawable(getResources().getDrawable(R.drawable.true_done));

        }
Du willst doch wenn Email nicht leehr und (&&) Email korrekt ist. Auf grün seten.
Sonnst soll der Pfeil grau bleiben.

So nun Überlege was du hier tust. Hast du auf beide Bedingungen geprüft oder nur auf eine?
 

wer112

Top Contributor
Du willst doch wenn Email nicht leehr und (&&) Email korrekt ist. Auf grün seten.
Sonnst soll der Pfeil grau bleiben.

So nun Überlege was du hier tust. Hast du auf beide Bedingungen geprüft oder nur auf eine?
Ich habe auf beide ja geprüft. Es wird auch grün, wenn beide Bedinnungen erfüllt sind.
Aber wenn ich was ändere und die BEdingungen nicht mehr stimmen, dann soll es wieder grau werden.

Deswegen habe ich es in den 2 Anweisungen es reingemacht, dass es rüchgängig gemacht wird. Aber es geht nicht.
 

wer112

Top Contributor
Dann zeige den ganzen Code davon! Du hast nur einen Check gezeigt und der ist so falsch, denn in dem Code in #20 prüfst Du nur eine Bedingung.
Java:
package ;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.Patterns;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.material.textfield.TextInputLayout;

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Login extends AppCompatActivity {

    TextView forgot, register;
    EditText email_edit, password_edit;

    CheckBox checkBox;
    String remember = "nein";


    Button login_btn;

    ImageView done;

    SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        sharedPreferences = getSharedPreferences("Login", Context.MODE_PRIVATE);
        String loginState = sharedPreferences.getString("prefLoginStat", "");

        if (loginState.equals("loggendin")) {
            startActivity(new Intent(Login.this, Fragment_Steuerung.class));


        }

        email_edit = (EditText)findViewById(R.id.email_input);
        password_edit = (EditText) findViewById(R.id.password_login);

        checkBox = (CheckBox)findViewById(R.id.remember_me);

        done = (ImageView)findViewById(R.id.imageView2);

        login_btn = (Button)findViewById(R.id.login_btn);
        login_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginPrüfung();
            }
        });





        register = (TextView)findViewById(R.id.register_login);

        forgot = (TextView) findViewById(R.id.forgot_password);

        forgot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Login.this, Reset_Passwort.class));
            }
        });

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Login.this, Registration.class));
            }
        });



    }

    private void LoginPrüfung(){
        String emailadresse = email_edit.getText().toString().trim();
        String password = password_edit.getText().toString().trim();

        Boolean all_right = true;

        if (emailadresse.isEmpty()){
            email_edit.setError("Email is Empty");
            email_edit.requestFocus();
            done.setImageDrawable(getResources().getDrawable(R.drawable.done_icon));


            all_right = false;

        }else if (!Patterns.EMAIL_ADDRESS.matcher(emailadresse).matches()){
            email_edit.setError("Email is not right");
            email_edit.requestFocus();
            done.setImageDrawable(getResources().getDrawable(R.drawable.done_icon));

            all_right = false;
        }

        if(!emailadresse.isEmpty()){
            done.setImageDrawable(getResources().getDrawable(R.drawable.true_done));

        }

        if (password.isEmpty()){
            password_edit.setError("Password is Empty");
            password_edit.requestFocus();
            all_right = false;

        }

        if (all_right){
            ProgressDialog progressDialog = new ProgressDialog(Login.this);
            progressDialog.setTitle("LogIn");
            progressDialog.setMessage("Please Wait");
            progressDialog.setCancelable(false);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.show();



            if(checkBox.isChecked()){
                remember = "Ja";
            }

            RequestQueue queue = Volley.newRequestQueue(Login.this);

            String url = "";


            StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    progressDialog.dismiss();

                    if(response.equals("LogIn")){

                        if(checkBox.isChecked()){
                            SiCookieStore2 siCookieStore = new SiCookieStore2(Login.this);
                            CookieManager cookieManager = new CookieManager((CookieStore) siCookieStore, CookiePolicy.ACCEPT_ALL);
                            CookieHandler.setDefault(cookieManager);

                            sharedPreferences = getApplicationContext().getSharedPreferences("Login", 0);
                            SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.putString("prefLoginStat", "loggendin");
                            editor.apply();

                            startActivity(new Intent(Login.this, Fragment_Steuerung.class));




                        }else{

                            CookieManager cookieManager = new CookieManager();
                            cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
                            CookieHandler.setDefault(cookieManager);

                            startActivity(new Intent(Login.this, Fragment_Steuerung.class));
                        }

                    }else{
                        AlertDialog alertDialog = new AlertDialog.Builder(Login.this).create();
                        alertDialog.setTitle("Login Error");
                        alertDialog.setMessage(response);
                        alertDialog.setCancelable(false);
                        alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Okay", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                alertDialog.dismiss();
                            }
                        });
                        alertDialog.show();
                    }

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    progressDialog.dismiss();

                    AlertDialog alertDialog = new AlertDialog.Builder(Login.this).create();
                    alertDialog.setTitle("Volly Error");
                    alertDialog.setMessage(error.toString());
                    alertDialog.setCancelable(false);
                    alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Okay", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            alertDialog.dismiss();
                        }
                    });
                    alertDialog.show();
                }
            }){
                @Nullable
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    HashMap<String, String> param = new HashMap<>();

                    param.put("email", emailadresse);
                    param.put("pass", password);
                    param.put("rem", "" + remember);

                    return param;
                }
            };

            queue.add(stringRequest);

        }

    }

    @Override
    public void onBackPressed() {
        Log.e("BackPressed", "Reset Password");
    }
}

Wenn der Button gedrückt wird, wird jedesmal neu geprüft. Wenn also was falsch ist, dann steht ja da in der if: done.setImageDrawable(getResources().getDrawable(R.drawable.done_icon)); also das es wieder grau werden soll.
 

Marinek

Bekanntes Mitglied
Also done_icon, gehe ich mal von aus, ist ein Icon, dass angibt, dass etwas falsch ist.

Das leite ich davon ab, weil
Java:
 if (emailadresse.isEmpty()){
anschließend das Icon auf done_icon gesetzt wird.

Das alleine machts schon schwer irgend ein Debug zu machen, weil done wäre ja schon etwas "Erledigt" im positiven Sinne oder?

Wie dem auch sei: Danach checkst du und nur, wenn die E-Mail befüllt ist, ob es einem Pattern nicht matched.

OK - Dann setzt du wieder Done (also fehler?)

Dann kommt eine neue Prüfung

Code:
 if(!emailadresse.isEmpty()){
            done.setImageDrawable(getResources().getDrawable(R.drawable.true_done));

        }

Und das setzt es auf true_done (ich gehe davon aus, dass dies dann Grün wird?.

Aber das negiert ja quasi deine vorherige Prüfung auf das Pattern. Denn wenn in der Mail "a" steht, dann ist egal, was der Pattern Check macht, du setzt es auf OK.

Ihmo müsste es else am ende heißen.

Gut, dass du den ganzen Quellcode gepostet hast.
 

Jw456

Top Contributor
Prüfen von beiden Bedingungen gleichzeitig habe ich die ganze Zeit gemeint.
In etwa so. Also eine Und Verknüpfung

Java:
 if(!emailadresse.isEmpty() && Patterns.EMAIL_ADDRESS.matcher(emailadresse).matches() ){
            done.setImageDrawable(getResources().getDrawable(R.drawable.true_done));
        } else{
            done.setImageDrawable(getResources().getDrawable(R.drawable.done_icon));
        }
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Text input into editText Android & Cross-Platform Mobile Apps 2
R Google Text-to-Speech Android & Cross-Platform Mobile Apps 5
R wie verwende ich Cloud Text-to-Speech? Android & Cross-Platform Mobile Apps 4
R Android Text-To-Speech Android & Cross-Platform Mobile Apps 4
ruutaiokwu Android In einem Android-“Spinner”-Element GLEICHZEITIG Bild (links) UND Text (rechts) anzeigen Android & Cross-Platform Mobile Apps 0
J Android App - Browser öffnen und Text eingeben/Button click auslösen Android & Cross-Platform Mobile Apps 10
M ImageButton: Bild ausblenden und Text anzeigen Android & Cross-Platform Mobile Apps 2
Flynn Text-File auf externe Speicherkarte schreiben Android & Cross-Platform Mobile Apps 1
F Aufkalbbaren Text Android & Cross-Platform Mobile Apps 4
B Android Text von Android zu PC senden? Android & Cross-Platform Mobile Apps 5
C Android Bei Text "Popup" anzeigen Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
M Android Edittext width passend zum Text Android & Cross-Platform Mobile Apps 1
L Android Theorie: Umwandeln von Text in Morsecode Android & Cross-Platform Mobile Apps 15
R Android Layout Bild mit Text Android & Cross-Platform Mobile Apps 13
N Android Änderung von tabwidget height lässt text verschwinden Android & Cross-Platform Mobile Apps 3
L Android Text aus Textfeld speichern Android & Cross-Platform Mobile Apps 5
J in android app text automatisch kopieren Android & Cross-Platform Mobile Apps 2
S Android Zufällige Text wiedergabe Android & Cross-Platform Mobile Apps 6
G Android zur Laufzeit den Text im Menü ändern Android & Cross-Platform Mobile Apps 3
K Android schwarzer Bildschirm beim Rendern von Text und Dreiecken Android & Cross-Platform Mobile Apps 9
S Android Canvas - drawText - Update Text in ActionListener Android & Cross-Platform Mobile Apps 8
N Gibt es eine opensource Speech-to-Text engine? Android & Cross-Platform Mobile Apps 3
M Text in txt-Datei schreiben und nach ABC sortieren? Android & Cross-Platform Mobile Apps 2
M Text in Canvas scrollen lassen Android & Cross-Platform Mobile Apps 13
G Text parsen String to Double Android & Cross-Platform Mobile Apps 2
G Bilder in drawable Ordner Android & Cross-Platform Mobile Apps 11

Ähnliche Java Themen

Neue Themen


Oben