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);                 }             }      }); 

`

  1. get value of edittext

  2. check desired answer

  3. 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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -