java - How to stay in same activity after clicking button in android? -


i trying develop simple feedback application. when user enters invalid data should show error. after error detected fields should clear , should stay on same activity should do?here's code:

      package com.example.feedback;  import android.os.bundle; import android.app.activity; import android.content.intent; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.radiogroup; import android.widget.toast;  public class feedback extends activity {     string s;     boolean fill=true;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_feedback);         final button bt1 = (button) findviewbyid(r.id.bt1);         final edittext tv2 = (edittext) findviewbyid(r.id.tv2);         final edittext tv1 = (edittext) findviewbyid(r.id.tv1);         final edittext tv3 = (edittext) findviewbyid(r.id.tv3);         final edittext tv4 = (edittext) findviewbyid(r.id.tv4);         final radiogroup rg = (radiogroup) findviewbyid(r.id.rg1);          bt1.setonclicklistener(new onclicklistener() {              @override             public void onclick(view arg0) {                 s = tv1.gettext().tostring();                 check();                 s = tv2.gettext().tostring();                 check();                 s = tv3.gettext().tostring();                 check();                 s = tv4.gettext().tostring();                 check();                 if (rg.getcheckedradiobuttonid() == -1){                     toast.maketext(feedback.this,"error",toast.length_long).show();                     }                  toast.maketext(feedback.this,"press again submit",toast.length_long).show();                 bt1.setonclicklistener(new onclicklistener() {                      @override                     public void onclick(view arg0) {                         startactivity(new intent(feedback.this,feedback2.class));                         // todo auto-generated method stub                      }                 });                   // todo auto-generated method stub              }              private void check() {                 if(s.matches("")){                     toast.maketext(feedback.this,"error",toast.length_long).show();                    }                  // todo auto-generated method stub              }         });     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.feedback, menu);         return true;     }  } 

this line:

  startactivity(new intent(feedback.this,feedback2.class)); 

after click, change activity. suggest check login success in onactivityresult method , if it's true start new activity


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -