java - Output in other layout -
somebody please me problem. i'm developing mobile grocery app thesis. used make more buttons because i'm beginner, , using buttons simplest way make app. want here make output in other layout, summary of item bought. way used checkbox determined might item buy. here's code.
baby_items (grocery category) serves parent button
public class baby_items extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_baby__items); } public void baby_diaper (view view) { intent = new intent(this, baby_diaper.class); startactivity(i); } public void baby_food (view view) { intent = new intent(this, baby_food.class); startactivity(i); } public void baby_milk (view view) { intent = new intent(this, baby_milk.class); startactivity(i); }
baby_diaper (children button)
public class baby_diaper extends actionbaractivity { arraylist<string> selection = new arraylist<string>(); textview final_text; intent = new intent(this, shopping_list.class); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_baby__diaper); final_text = (textview)findviewbyid(r.id.final_result_shopping); final_text.setenabled(false); } public void selectitem (view view) { boolean checked = ((checkbox) view) .ischecked(); switch (view.getid()) { case r.id.pampers: if(checked) {selection.add("pampers");} else { selection.remove ("pampers"); } break; case r.id.huggies: if(checked) {selection.add("huggies");} else { selection.remove ("huggies"); } break; case r.id.johnsons: if(checked) {selection.add("johnsons");} else { selection.remove ("johnsons"); } break; case r.id.supreme: if(checked) {selection.add("supreme");} else { selection.remove ("supreme"); } break; } } public void addtocart(view view){ string final_shopping_selection = ""; (string selections : selection){ final_shopping_selection = final_shopping_selection + selections + "\n"; } final_text.settext(final_shopping_selection); final_text.setenabled(true); }
baby item xml
<relativelayout 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" tools:context="com.example.admin.mobile_grocery.baby_items" android:id="@+id/baby_items"> <imagebutton android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/diapers" android:src="@drawable/cloth_diaper_pic" android:scaletype="centercrop" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="baby_diaper" /> <imagebutton android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/baby_food" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:src="@drawable/baby_food" android:scaletype="centercrop" android:onclick="baby_food" /> <imagebutton android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/baby_milk" android:layout_alignparenttop="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:src="@drawable/milk" android:scaletype="centercrop" android:onclick="baby_milk" />
baby_diaper xml
<relativelayout 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" tools:context="com.example.admin.mobile_grocery.baby_diaper" android:id="@+id/baby_diaper"> <checkbox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pampers" android:id="@+id/pampers" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_margintop="52dp" android:checked="false" android:onclick="selectitem" /> <checkbox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/huggies" android:id="@+id/huggies" android:layout_below="@+id/pampers" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:checked="false" android:onclick="selectitem" /> <checkbox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/johnsons" android:id="@+id/johnsons" android:layout_below="@+id/huggies" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:checked="false" android:onclick="selectitem" android:inputtype="textnosuggestions" /> <checkbox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/supreme" android:id="@+id/supreme" android:layout_below="@+id/johnsons" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:checked="false" android:onclick="selectitem" android:inputtype="textnosuggestions" /> <button style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/addtocart" android:id="@+id/addtocart" android:layout_alignparenttop="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:onclick="ocaddtocart" android:inputtype="textnosuggestions" />
shopping list xml (i want summary items here in shopping list activity)
<relativelayout 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" tools:context="com.example.admin.mobile_grocery.shopping_list" android:id="@+id/shopping_list_layout"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="shopping list" android:id="@+id/shopping_list" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello shoppers!" android:id="@+id/final_result_shopping" android:layout_margintop="33dp" android:layout_below="@+id/reservation_list" android:layout_alignparentleft="true" android:layout_alignparentstart="true" />
shopping list java
no code added
manifest
<?xml version="1.0" encoding="utf-8"?>
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mobile_grocery" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".login" android:label="@string/title_activity_login" > </activity> <activity android:name=".baby_items" android:label="@string/title_activity_baby__items" > </activity> <activity android:name=".baking" android:label="@string/title_activity_baking" > </activity> <activity android:name=".beverages" android:label="@string/title_activity_beverages" > </activity> <activity android:name=".bakery" android:label="@string/title_activity_bakery" > </activity> <activity android:name=".canned_goods" android:label="@string/title_activity_canned__goods" > </activity> <activity android:name=".condiments" android:label="@string/title_activity_condiments" > </activity> <activity android:name=".dairy" android:label="@string/title_activity_dairy" > </activity> <activity android:name=".frozen_foods" android:label="@string/title_activity_frozen__foods" > </activity> <activity android:name=".miscellaneous" android:label="@string/title_activity_miscellaneous" > </activity> <activity android:name=".non_food_items" android:label="@string/title_activity_non__food__items" > </activity> <activity android:name=".pasta_rice" android:label="@string/title_activity_pasta__rice" > </activity> <activity android:name=".snacks" android:label="@string/title_activity_snacks" > </activity> <activity android:name=".baby_diaper" android:label="@string/title_activity_baby__diaper" > </activity> <activity android:name=".baby_food" android:label="@string/title_activity_baby__food" > </activity> <activity android:name=".baby_milk" android:label="@string/title_activity_baby__milk" > </activity> <activity android:name=".bakery_bread" android:label="@string/title_activity_bakery__bread" > </activity> <activity android:name=".bakery_cake" android:label="@string/title_activity_bakery__cake" > </activity> <activity android:name=".bakery_cookies" android:label="@string/title_activity_bakery__cookies" > </activity> <activity android:name=".bakery_donut" android:label="@string/title_activity_bakery__donut" > </activity> <activity android:name=".bakery_muffins" android:label="@string/title_activity_bakery__muffins" > </activity> <activity android:name=".bakery_pie" android:label="@string/title_activity_bakery__pie" > </activity> <activity android:name=".beverages_coffee" android:label="@string/title_activity_beverages__coffee" > </activity> <activity android:name=".beverages_juice" android:label="@string/title_activity_beverages__juice" > </activity> <activity android:name=".beverages_soda" android:label="@string/title_activity_beverages__soda" > </activity> <activity android:name=".beverages_tea" android:label="@string/title_activity_beverages__tea" > </activity> <activity android:name=".beverages_water" android:label="@string/title_activity_beverages__water" > </activity> <activity android:name=".baking_flour" android:label="@string/title_activity_baking__flour" > </activity> <activity android:name=".baking_icing" android:label="@string/title_activity_baking__icing" > </activity> <activity android:name=".baking_sugar" android:label="@string/title_activity_baking__sugar" > </activity> <activity android:name=".canned_goods_fruits_and_veggies" android:label="@string/title_activity_canned__goods__fruits__and__veggies" > </activity> <activity android:name=".canned_goods_sauces" android:label="@string/title_activity_canned__goods__sauces" > </activity> <activity android:name=".canned_goods_tuna" android:label="@string/title_activity_canned__goods__tuna" > </activity> <activity android:name=".condiments_ketchup" android:label="@string/title_activity_condiments__ketchup" > </activity> <activity android:name=".condiments_mustard" android:label="@string/title_activity_condiments__mustard" > </activity> <activity android:name=".condiments_soy_sauce" android:label="@string/title_activity_condiments__soy__sauce" > </activity> <activity android:name=".condiments_vinegar" android:label="@string/title_activity_condiments__vinegar" > </activity> <activity android:name=".dairy_cheese" android:label="@string/title_activity_dairy__cheese" > </activity> <activity android:name=".dairy_dairymilk" android:label="@string/title_activity_dairy_dairymilk" > </activity> <activity android:name=".dairy_egg" android:label="@string/title_activity_dairy__egg" > </activity> <activity android:name=".frozen_food_ice_cream" android:label="@string/title_activity_frozen__food__ice__cream" > </activity> <activity android:name=".miscellaneous_battery" android:label="@string/title_activity_miscellaneous__battery" > </activity> <activity android:name=".non_food_items_liquid_detergent" android:label="@string/title_activity_non__food__items__liquid__detergent" > </activity> <activity android:name=".non_food_items_dishwashing_liquid" android:label="@string/title_activity_non__food__items__dishwashing__liquid" > </activity> <activity android:name=".non_food_items_plates_n_cups" android:label="@string/title_activity_non__food__items__plates_n__cups" > </activity> <activity android:name=".non_food_items_soap" android:label="@string/title_activity_non__food__items__soap" > </activity> <activity android:name=".non_food_items_tissue" android:label="@string/title_activity_non__food__items__tissue" > </activity> <activity android:name=".pasta_rice_macaroni" android:label="@string/title_activity_pasta__rice__macaroni" > </activity> <activity android:name=".pasta_rice_spaghetti" android:label="@string/title_activity_pasta__rice__spaghetti" > </activity> <activity android:name=".pasta_rice_rice" android:label="@string/title_activity_pasta__rice__rice" > </activity> <activity android:name=".snacks_chips" android:label="@string/title_activity_snacks__chips" > </activity> <activity android:name=".my_profile_list" android:label="@string/title_activity_my__profile__list" > </activity> <activity android:name=".shopping_list" android:label="@string/title_activity_shopping__list" > </activity> <activity android:name=".reservation_list" android:label="@string/title_activity_reservation__list" > </activity> <activity android:name=".credit_list" android:label="@string/title_activity_credit__list" > </activity> </application>
logcat error ###
09-30 12:28:10.297 2019-2210/? e/watchdog﹕ !@sync 9045 09-30 12:28:37.827 4074-4074/? e/mtpservice﹕ in mtpapp onreceive:android.intent.action.battery_changed 09-30 12:28:37.827 4074-4074/? e/mtpservice﹕ battplugged type : 2 09-30 12:28:40.297 2019-2210/? e/watchdog﹕ !@sync 9046 09-30 12:29:10.302 2019-2210/? e/watchdog﹕ !@sync 9047 09-30 12:29:17.812 4074-4074/? e/mtpservice﹕ in mtpapp onreceive:android.intent.action.battery_changed 09-30 12:29:17.812 4074-4074/? e/mtpservice﹕ battplugged type : 2 09-30 12:29:40.302 2019-2210/? e/watchdog﹕ !@sync 9048 09-30 12:29:42.902 24687-24687/? e/dalvikvm﹕ not find class 'android.app.notification$action$builder', referenced method b.a 09-30 12:29:43.032 24687-24687/? e/dalvikvm﹕ not find class 'android.graphics.drawable.rippledrawable', referenced method b.a 09-30 12:29:43.242 24687-24687/? e/dalvikvm﹕ not find class 'android.app.notification$action$builder', referenced method b.a 09-30 12:29:43.332 24687-24687/? e/dalvikvm﹕ not find class 'android.transition.transition', referenced method b.a 09-30 12:29:43.332 24687-24687/? e/dalvikvm﹕ not find class 'android.transition.transition', referenced method b.a 09-30 12:29:43.332 24687-24687/? e/dalvikvm﹕ not find class 'android.transition.transition', referenced method b.a 09-30 12:29:43.407 24687-24687/? e/dalvikvm﹕ not find class 'android.app.remoteinput[]', referenced method b.a 09-30 12:29:43.442 24687-24687/? e/dalvikvm﹕ not find class 'android.transition.transition', referenced method b.b 09-30 12:29:57.947 4074-4074/? e/mtpservice﹕ in mtpapp onreceive:android.intent.action.battery_changed 09-30 12:29:57.947 4074-4074/? e/mtpservice﹕ battplugged type : 2 09-30 12:30:10.307 2019-2210/? e/watchdog﹕ !@sync 9049
how passing extras in startactivity(new intent(chooseitems.this,shoppinglist.class)
call?
somethinh this:
intent shoppinglistintent = new intent(chooseitems.this,shoppinglist.class); shoppinglistintent.putextra("item1","diaper"); shoppinglistintent.putextra("item2","another item");
//or add arraylist of items: shoppinglistintent.putstringarraylistextra("items",arritems);
startactivity(shoppinglistintent);
Comments
Post a Comment