java - Building First App Tutorial Button not working -


so, i'm trying make android app tutorial on android page, build first app.(https://developer.android.com/training/basics/firstapp/index.html?hl=it) i'm doing on intellji, found bit different.. so, made third part, make interface, things got weird in forth part, create activity.

i created displaymessageactivity.java file, , copied code site. problem found because file wasn't made automatically, or other reason, intellij didn't know r.id.action_settings , container. so, looked on code, , figured now, "start activity" section, needed "oncreate" method. greyed out theonoptionsitemselected boolean now.

when ran this, however, interface came out send button didn't when suppose show new page message... so, wondering how fixed.

these codes

myactivity.java

package com.example.myfirstapp;  import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext;  public class myactivity extends activity { public final static string extra_message = "com.example.myfirstapp.message";  button button; @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main); } public void sendmessage(view view) {     intent intent = new intent(this, displaymessageactivity.class);     edittext edittext = (edittext) findviewbyid(r.id.edit_message);     string message = string.valueof(edittext.gettext());     intent.putextra(extra_message, message); } } 

displaymessageactivity.java

    package com.example.myfirstapp;  import android.app.activity; import android.app.fragment; import android.content.intent; import android.os.bundle; import android.view.layoutinflater; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.textview; import com.example.myfirstapp.r;  public class displaymessageactivity extends activity{ @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      intent intent = getintent();     string message = intent.getstringextra(myactivity.extra_message);      textview textview = new textview(this);     textview.settextsize(40);     textview.settext(message);      setcontentview(textview); } public static class placeholderfragment extends fragment {      public placeholderfragment() { }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.activity_display_message, container, false);         return rootview;     } } } 

you created intent in sendmessage, forgot start activity it. add

startactivity(intent); 

at end of function , should work (if layout file correct of course).

see start second activity


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -