I created an Android application with two activities, but cannot switch back from the second activity to the first -
i created android application 2 activities, somehow buttons on second activity not seem work properly. button on first activity (a map activity , button add infromat takes users second activity information entry screen) works fine, neither button on second activity seems have effect... can't onclick toast message work.
public class mapsactivity extends fragmentactivity implements onmapreadycallback , locationlistener { public void addmapinfo(view view) { intent intent = new intent(this, informationinputactivity.class); latlng providedlocation = current; bundle args = new bundle(); args.putparcelable("provided_location", providedlocation); intent.putextra("bundle", args); startactivityforresult(intent, 1); } public void onactivityresult (int requestcode, int resultcode, intent data){ toast.maketext(this, "back cheese!", toast.length_long).show(); if (requestcode != 1){ toast.maketext(this, "oops... shouldn't happen", toast.length_long).show(); } else{ setcontentview(r.layout.activity_maps); informationpoint informationpoint = (informationpoint) data.getserializableextra("information_point"); informationpoint.display(mymap); } } } the second activity brings on layout screen, , sets proper options edittext field, know gets control... that's it. there no toast message of methods (i still toasts when location update info received on first activity instead), , neither radio button or submit buttons seem work, i'm not getting result , control in first activity. (previously, used able toast on ever on checked option on radio button, doesn't seem work either). trying send activity result aborts application (since added finish() second activity).
/* java */ package com.example.m.googlemapappfirst; import android.content.intent; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.radiobutton; import android.widget.textview; import android.widget.toast; import com.google.android.gms.maps.model.latlng; import org.w3c.dom.text; public class informationinputactivity extends actionbaractivity { edittext edittext; string content = ""; latlng providedlocation; public infotype infotype = infotype.no_info; informationpoint informationpoint; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_information_input); intent intent = getintent(); bundle bundle = getintent().getparcelableextra("bundle"); providedlocation = bundle.getparcelable("provided_location"); string message = string.valueof(providedlocation); edittext = (edittext)findviewbyid(r.id.description); edittext.sethorizontallyscrolling(false); edittext.setmaxlines(5); toast.maketext(this, "enter cheese info", toast.length_long); } public void onradiobuttonclicked(view view) { // button checked? boolean checked = ((radiobutton) view).ischecked(); toast.maketext(this,"you selected cheese", toast.length_long); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_information_input, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } public void addpicturehandler(view view){ toast.maketext(this, "i take pictures of cheese", toast.length_long).show(); } public void submithandler(view view){ content = edittext.gettext().tostring(); toast.maketext(this, "add cheese info", toast.length_long).show(); if(infotype == infotype.no_info){ toast.maketext(this, "please select information type", toast.length_long).show(); } else if(content.equals("")){ toast.maketext(this, "please write description", toast.length_long).show(); } informationpoint = new informationpoint(providedlocation, infotype, content); intent returnintent = new intent(this, mapsactivity.class); returnintent.putextra("information_point", informationpoint); this.setresult(1, returnintent); finish(); /* added after original post, makes app crash consistently */ } } here's xml layout file second activity:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.example.m.googlemapappfirst.informationinputactivity"> <textview android:text="@string/instructions" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <radiogroup xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <radiobutton android:id="@+id/radio_swiss" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/swiss" android:onclick="onradiobuttonclicked"/> <radiobutton android:id="@+id/radio_american" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/american" android:onclick="onradiobuttonclicked"/> <radiobutton android:id="@+id/radio_gruyere" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/gruyere" android:onclick="onradiobuttonclicked"/> <radiobutton android:id="@+id/radio_cheddar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cheddar" android:onclick="onradiobuttonclicked"/> </radiogroup> <textview android:text="@string/instructions2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <edittext android:id="@+id/description" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_weight="1" android:hint="@string/type_here" android:inputtype="text" android:imeoptions="actiondone" android:maxlines ="4" android:maxlength ="2000" android:scrollhorizontally="false" /> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" android:orientation="horizontal"> <button android:id="@+id/take_picture_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="add picture" android:onclick="addpicturehandler" /> <button android:id="@+id/submit_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="report information" android:onclick="submithandler" /> </linearlayout>
i didn't see problem missing invocation of show() after toast creation, this:
toast.maketext(this, "oops... shouldn't happen", toast.length_long).show();
Comments
Post a Comment