java - Android button onClickListener -


i new android development. trying open new activity in onclicklistener method. should write , how onclicklistener method work?

this task can accomplished using 1 of android's main building block named intents , 1 of methods public void startactivity (intent intent) belongs activity class.

an intent abstract description of operation performed. can used startactivity launch activity, broadcastintent send interested broadcastreceiver components, , startservice(intent) or bindservice(intent, serviceconnection, int) communicate background service.

an intent provides facility performing late runtime binding between code in different applications. significant use in launching of activities, can thought of glue between activities. passive data structure holding abstract description of action performed.

refer official docs -- http://developer.android.com/reference/android/content/intent.html

public void startactivity (intent intent) -- used launch new activity.

so suppose have 2 activity class --

  1. presentactivity -- current activity want go second activity.

  2. nextactivity -- next activity on want move.

so intent this

intent(presentactivity.this, nextactivity.class) 

finally complete code

public class presentactivity extends activity {   protected void oncreate(bundle icicle) {     super.oncreate(icicle);      setcontentview(r.layout.content_layout_id);      final button button = (button) findviewbyid(r.id.button_id);     button.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {               // perform action on click                  intent activitychangeintent = new intent(presentactivity.this, nextactivity.class);                // currentcontext.startactivity(activitychangeintent);                presentactivity.this.startactivity(activitychangeintent);             }           });   } } 

i hope can understand , if facing problem me here only. happy help.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -