M
MatthiasKramer
Ambitioniertes Mitglied
- 3
Moin,
ich mache grade eine Login Activity. Der Username ist in der App schon festgelegt. Provisorisch habe ich einfach mal "user" gewählt.
Das Passwort werde ich später auch noch festlegen, aber um zu schauen ob er das Passwort-Feld überhaupt ausliest und erkennt habe ich einfach mal ein Toast dazu getan.
Also folgendes Prinzip: Der User gibt den username ein, also user danach gibt er das Passwort ein, z.B. abc (Da das Passwort ja noch nicht festgelegt ist).
Anschließend klickt er auf "Login". Nun soll er erkennen, wenn als username "user" angegeben ist, soll er das Passwort auslesen und als Toast wiedergeben. Wenn als username irgendein anderer beliebiger Name angegeben ist (z.B. DonaldDuck) soll ein Toast "Invalid password or username" ausgeben.
Was ich mache, ist: Ich gebe als username "user" ein, als passwort "abc".
Was die Reaktion darauf ist: Der Toast zeigt "Invalid password or username" an, obwohl der username richtig ist! Das Passwort sollte ja so oder so richtig sein, weil das ja noch nicht festgelegt ist.
Hier ist mal die Activity:
Edit:
Öhm, ich hoffe ihr könnt das Bild sehen, ich kanns nicht o.0
Falls nicht, hier ist der Originallink: http://s14.directupload.net/file/d/3038/c6oqjh6m_png.htm
ich mache grade eine Login Activity. Der Username ist in der App schon festgelegt. Provisorisch habe ich einfach mal "user" gewählt.
Das Passwort werde ich später auch noch festlegen, aber um zu schauen ob er das Passwort-Feld überhaupt ausliest und erkennt habe ich einfach mal ein Toast dazu getan.
Also folgendes Prinzip: Der User gibt den username ein, also user danach gibt er das Passwort ein, z.B. abc (Da das Passwort ja noch nicht festgelegt ist).
Anschließend klickt er auf "Login". Nun soll er erkennen, wenn als username "user" angegeben ist, soll er das Passwort auslesen und als Toast wiedergeben. Wenn als username irgendein anderer beliebiger Name angegeben ist (z.B. DonaldDuck) soll ein Toast "Invalid password or username" ausgeben.
Was ich mache, ist: Ich gebe als username "user" ein, als passwort "abc".
Was die Reaktion darauf ist: Der Toast zeigt "Invalid password or username" an, obwohl der username richtig ist! Das Passwort sollte ja so oder so richtig sein, weil das ja noch nicht festgelegt ist.
Hier ist mal die Activity:
Code:
[SIZE=2][COLOR=#7f0055][B][SIZE=2][COLOR=#7f0055]package[/COLOR][/SIZE][/B]
[LEFT][/COLOR][/SIZE][SIZE=2]de.projekt.irgendeinprojekt;[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.app.Activity;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.os.Bundle;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.view.Menu;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.view.View;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.view.View.OnClickListener;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.widget.Button;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.widget.EditText;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2]android.widget.Toast;[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]
[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] IeP [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity {[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] EditText [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]password[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Button [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]btnLogIn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] EditText [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]username[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreate(Bundle savedInstanceState) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE]
[SIZE=2]setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]addListenerOnButton();[/SIZE]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]boolean[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreateOptionsMenu(Menu menu) {[/SIZE]
[SIZE=2]getMenuInflater().inflate(R.menu.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], menu);[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] addListenerOnButton() {[/SIZE]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]username[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (EditText) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]editText1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]password[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (EditText) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]editText2[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]btnLogIn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (Button) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]button1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]btnLogIn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnClickListener(){[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick (View v){[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]username[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText().toString() == [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"user"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]){[/SIZE]
[SIZE=2]Toast.[I]makeText[/I](IeP.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Password: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]password[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText(), Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_LONG[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]).show(); [/SIZE]
[SIZE=2]}[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]{[/SIZE]
[SIZE=2]Toast.[I]makeText[/I](IeP.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Invalid password or username"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_LONG[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]).show();[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]}[/SIZE]
[LEFT][SIZE=2]});[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
Hier ein Screenshot vom Login-Fenster:
Edit:
Öhm, ich hoffe ihr könnt das Bild sehen, ich kanns nicht o.0
Falls nicht, hier ist der Originallink: http://s14.directupload.net/file/d/3038/c6oqjh6m_png.htm