How to pass checkboxes in different activities to one single activity in android? -
i making android app in there different cities in different activities. example, there 1 activity dalhousie , activity shimla. , in each activity there 1 heart shaped checkbox, in instagram. if check check boxes, city appear in activity profileactivity.java has list of favorite cities have checked. don't know how intent different activities 1 single activity.
here code dalhousieactivity.java
package com.example.srushtee.dummy; import android.app.activity; import android.content.intent; import android.content.sharedpreferences; import android.support.v4.view.viewpager; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.text.method.scrollingmovementmethod; import android.util.log; import android.view.view; import android.widget.button; import android.widget.checkbox; import android.widget.compoundbutton; import android.widget.textview; import me.relex.circleindicator.circleindicator; public class dalhousieactivity extends appcompatactivity { private viewpager viewpager; private customswipeadapter adapter; private static int currentpage = 0; private int[] img; private checkbox favouritebtn; private textview textview; boolean flag=false; private button continuebooking; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_dalhousie); boolean ischecked = getbooleanfrompreferences("ischecked"); img = new int[]{r.drawable.dalhousie, r.drawable.dalhousie3, r.drawable.dalhousie2, r.drawable.dalhousie1}; viewpager = (viewpager) findviewbyid(r.id.view_pager); adapter = new customswipeadapter(dalhousieactivity.this, img); viewpager.setadapter(adapter); circleindicator indicator = (circleindicator) findviewbyid(r.id.indicator); indicator.setviewpager(viewpager); viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { } @override public void onpageselected(int position) { currentpage = 1; } @override public void onpagescrollstatechanged(int i) { if (i == viewpager.scroll_state_idle) { int pagecount = img.length; if (currentpage == 0) { viewpager.setcurrentitem(pagecount - 1, false); } else if (currentpage == pagecount - 1) { viewpager.setcurrentitem(0, false); } } } }); favouritebtn = (checkbox) findviewbyid(r.id.buttonfav); log.i("start", "" + ischecked); favouritebtn.setchecked(ischecked); favouritebtn.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton view, boolean ischecked) { log.i("boolean", "" + ischecked); dalhousieactivity.this.putbooleaninpreferences(ischecked, "ischecked"); flag=true; intent i=new intent(getapplicationcontext(),profileactivity.class); i.putextra("dalhousie",flag); } }); continuebooking=(button) findviewbyid(r.id.continue_booking); continuebooking.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent i=new intent(dalhousieactivity.this,confirmationactivity.class); startactivity(i); } }); } public void putbooleaninpreferences(boolean ischecked,string key){ sharedpreferences sharedpreferences = this.getpreferences(activity.mode_private); sharedpreferences.editor editor = sharedpreferences.edit(); editor.putboolean(key, ischecked); editor.commit(); } public boolean getbooleanfrompreferences(string key){ sharedpreferences sharedpreferences = this.getpreferences(activity.mode_private); boolean ischecked = sharedpreferences.getboolean(key, false); return ischecked; } }
and here code profileactivity.class
package com.example.srushtee.dummy; import android.content.intent; import android.os.handler; import android.os.process; import android.provider.contactscontract; import android.support.annotation.nonnull; import android.support.design.widget.navigationview; import android.support.v4.view.gravitycompat; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbardrawertoggle; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.support.v7.widget.toolbar; import android.view.menuitem; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.listview; import android.widget.textview; import android.widget.toast; import com.google.firebase.auth.firebaseauth; import com.google.firebase.auth.firebaseuser; import java.util.arraylist; import java.util.list; public class profileactivity extends appcompatactivity { private drawerlayout mdrawerlayout; private actionbardrawertoggle mtoggle; private boolean backpressedtoexitonce; private boolean doublebacktoexitpressedonce; private navigationview navigationview; private firebaseauth firebaseauth; private button upload_btn; boolean flag=false; listview listview; string favname; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_profile); firebaseauth=firebaseauth.getinstance(); if(firebaseauth==null) { finish(); startactivity(new intent(this,mainactivity.class)); } firebaseuser user=firebaseauth.getcurrentuser(); getsupportactionbar().setdisplayhomeasupenabled(true); navigationview=(navigationview) findviewbyid(r.id.navigation_view); navigationview.setnavigationitemselectedlistener(new navigationview.onnavigationitemselectedlistener() { @override public boolean onnavigationitemselected(@nonnull menuitem item) { if(item.ischecked()) item.setchecked(false); else item.setchecked(true); mdrawerlayout.closedrawers(); switch(item.getitemid()) { case r.id.nav_account: toast.maketext(profileactivity.this,"called account",toast.length_short).show(); //startactivity(new intent(profileactivity.this,account.class)); return true; case r.id.nav_logout: signout(); return true; case r.id.nav_cities: startactivity(new intent(profileactivity.this,citiesactivity.class)); return true; default: toast.maketext(profileactivity.this,"default",toast.length_short).show(); return true; } } }); actionbardrawertoggle actionbardrawertoggle = new actionbardrawertoggle(this,mdrawerlayout,r.string.open, r.string.close){ @override public void ondrawerclosed(view drawerview) { // code here triggered once drawer closes dont want happen leave blank super.ondrawerclosed(drawerview); } @override public void ondraweropened(view drawerview) { // code here triggered once drawer open dont want happen leave blank super.ondraweropened(drawerview); } }; mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawerlayout); mtoggle=new actionbardrawertoggle(this,mdrawerlayout,r.string.open,r.string.close); mdrawerlayout.adddrawerlistener(mtoggle); mtoggle.syncstate(); mtoggle.settoolbarnavigationclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mdrawerlayout.opendrawer(gravitycompat.start); } }); //list<list_item> data = new arraylist<>(); /* (int j = 0; j < 6; j++) { list_item item = new list_item(); item.setimageresid(place_image[j]); item.settitle(place_name[j]); item.setid(place_name[j]); item.setstatus(place_desc[j]); data.add(item); } list_data = (arraylist) data; //data stored , retrieved until rec_view = (recyclerview) findviewbyid(r.id.places_recyler_view); rec_view.setlayoutmanager(new linearlayoutmanager(this)); adapter = new derp_adapter(data, this); rec_view.setadapter(adapter); adapter.setitemclickcallback(this);*/ upload_btn=(button) findviewbyid(r.id.upload_photo_btn); upload_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { startactivity(new intent(profileactivity.this,uploadphotoactivity.class)); } }); } private void signout() { if(firebaseauth!=null) { firebaseauth.signout(); } finish(); startactivity(new intent(this,mainactivity.class)); } @override public boolean onoptionsitemselected(menuitem item) { if(mtoggle.onoptionsitemselected(item)) { return true; } return super.onoptionsitemselected(item); } public void onbackpressed() { if (doublebacktoexitpressedonce) { movetasktoback(true); process.killprocess(process.mypid()); system.exit(1); } this.doublebacktoexitpressedonce = true; toast.maketext(this, "press again exit", toast.length_short).show(); new handler().postdelayed(new runnable() { @override public void run() { doublebacktoexitpressedonce = false; } }, 1000); } }
Comments
Post a Comment