jeudi 3 août 2017

How can I set my enum with the value the user enter in a editText?

I have a editText where the users enter a number between 0 and 10. Depending on their entered number the enum (knowledge) will set.
Here's my code so far:

public int fromUserInput() {
    TextView eWissen = (TextView) findViewById(R.id.editText_eingabeWissentsstand);
    eWissen.getText().toString() == Zahl;
    return Zahl;
}

private enum Wissenstand
{
    BEGINNER, FORTGESCHRITTENER, PRO, GRANDMASTER;

    static Wissenstand fromUserInput(final int input)
    {
        if (input >= 10) {
            return GRANDMASTER;
        } else if (input >= 7) {
            return PRO;
        } else if (input >= 4) {
            return FORTGESCHRITTENER;
        } else if (input >= 0) {
            return BEGINNER;
        } else {
            TextView uWissen = (TextView) findViewById(R.id.textView_Wissen_Titel);
            TextView pWarung = (TextView) findViewById(R.id.textView_Wissen);


        uWissen.setText("Fehler gefunden!");
        uWissen.getResources().getColor(android.R.color.holo_red_dark);
        pWarung.setText("Gib eine Zahl von 0 bis 10 ein!\n0,5-er Schritte sind nicht erlaubt!\nWeitere Informationen kannst du der Legende entnehmen!");
        pWarung.getResources().getColor(android.R.color.holo_red_light);
        }
        return null;
    }
}

Additionally I can't use "findViewById" in my "static Wissenstand from UserInput(Final int input) {...}" method for some reason.
If you need something tell me, I help wherever I can.

Aucun commentaire:

Enregistrer un commentaire