java - correct text input to next activity -
i new programmer , looking make sort of quiz app first app. questions right answer send user next activity. figured out how edit buttons not sure add java file or xml file allow next activity (screen) opened up.
this layout far. have decided password input answer question stored within app. not sure if right approach?
`
<textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="question" /> <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview1" android:layout_centerhorizontal="true" android:layout_margintop="78dp" android:ems="10" android:inputtype="textpassword" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview1" android:layout_centerhorizontal="true" android:text="answer" />
`
thanks in advance rendered!
@kanwaljit sngh
i getting multiple errors "button cannot resolved type" , "r cannot resolved variable" these mean?
`import android.os.bundle; import android.app.activity; import android.view.menu;
public class startscreen extends activity {
edittext edittext1 = (edittext) findviewbyid(r.id.edittext1); button btn = (button) findviewbyid(r.id.button); btn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub string answer = edittext1.gettext().tostring().trim(); if (answer.equals("desired answer")) { intent = new intent(getapplicationcontext(), correctansweractivity.class); startactivity(i); } else { intent = new intent(getapplicationcontext(), wrongansweractivity.class); startactivity(i); } } });
`
check desired answer
if true, redirect next activity
eg :
if(edittext1.gettext().tostring().equalsignorecase("desiredanswer") { startactivity(new intent(this,nextactivity.class)); } else { toast.maketext(this,"wrong answer",2000).show(); }
Comments
Post a Comment