java - I am attempting to store user input in one activity to a listview in another activity. It wont work -


i have been attempting store data listview separate items isn't working. if understands android studio , issue me helpful. think organization in mainactivity.java might why doesn't work. mainactivity.java has listview while newtask.java user inputs data such name of task , due date. have used startactivityforresult() still having issue. please help.

mainactivity.java

package com.example.shaan.todoer;  import android.app.activity; import android.content.context; 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.arrayadapter; import android.widget.button; import android.widget.edittext; import android.widget.listview; import android.widget.textview;  import java.util.arraylist; import java.util.list;   public class mainactivity extends activity {  arraylist<string> list = new arraylist<string>();  arrayadapter<string> adapter;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     //things still left do:     //prevent overriding of items     //activate delete tasks on hard click of items     //fit name, date, , priority on 1 line of list     //attempt able sort items in listview      button firstbutton = (button) findviewbyid(r.id.add_task_group);      firstbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             startactivity(new intent(mainactivity.this, calendarviewactivity.class));         }     }); }      protected void onactivityresult(int requestcode, int resultcode, intent data) {         adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_multiple_choice, list);         listview listviewtodo = (listview) findviewbyid(r.id.listviewtodo);         listviewtodo.setadapter(adapter);         intent = new intent(this, newtask.class);         startactivityforresult(i, 1);         if(requestcode == 1) {             if(resultcode == result_ok) {                 string str = data.getstringextra("type_task_name");                 string str1 = data.getstringextra("text_date");                 int seek = data.getintextra("seekbar", 0);                  adapter.add(str);             }             adapter.notifydatasetchanged();         }     }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_main, 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); } } 

newtask.java

package com.example.shaan.todoer;  import java.util.calendar;  import android.app.activity; import android.app.datepickerdialog; import android.content.intent; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.datepicker; import android.widget.edittext; import android.widget.listview; import android.widget.seekbar; import android.widget.seekbar.onseekbarchangelistener; import android.widget.textview; import android.widget.toast;   public class newtask extends activity implements onclicklistener { button set_date;  private int calyear, calmonth, calday; private seekbar slider; private textview sliderlevel;   public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_new_task);     initialize();      button cancel_new_task = (button) findviewbyid(r.id.cancel_new_task);     cancel_new_task.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             startactivity(new intent(newtask.this, mainactivity.class));         }     });      sliderlevel.settext("priority level: " + slider.getprogress() + "/" + slider.getmax());     slider.setonclicklistener(this);     slider.setonseekbarchangelistener(new onseekbarchangelistener() {         int work = 0;          @override         public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) {             work = progress;             toast.maketext(getapplicationcontext(), "priority level changing", toast.length_short);         }          @override         public void onstarttrackingtouch(seekbar seekbar) {             toast.maketext(getapplicationcontext(), "started tracking slider", toast.length_short);          }          @override         public void onstoptrackingtouch(seekbar seekbar) {             sliderlevel.settext("priority level: " + work + "/" + slider.getmax());             toast.maketext(getapplicationcontext(), "stopped tracking slider", toast.length_short);         }        });   }  private void initialize() {     slider = (seekbar) findviewbyid(r.id.seekbar);     sliderlevel = (textview) findviewbyid(r.id.textview7);     set_date = (button) findviewbyid(r.id.set_date);     text_date = (edittext) findviewbyid(r.id.text_date);     set_date.setonclicklistener(this);     text_date.setonclicklistener(this);     create_task = (button) findviewbyid(r.id.create_task);     type_task_name = (edittext) findviewbyid(r.id.type_task_name);     seekbar = (seekbar) findviewbyid(r.id.seekbar);     text_date = (edittext) findviewbyid(r.id.text_date);  }  button create_task; edittext type_task_name; seekbar seekbar; edittext text_date;   @override public void onclick(view v) {     if (v == set_date) {         final calendar cal = calendar.getinstance();         calyear = cal.get(calendar.year);         calmonth = cal.get(calendar.month);         calday = cal.get(calendar.day_of_month);          datepickerdialog date = new datepickerdialog(this, new datepickerdialog.ondatesetlistener() {              @override             public void ondateset(datepicker look, int year, int month, int day) {                 text_date.settext((month + 1) + "/" + (day) + "/" + year);              }         }, calyear, calmonth, calday);         date.show();     } }  public void buttonaddclick(view v) {     startactivity(new intent(newtask.this, mainactivity.class));     intent = new intent();     i.putextra("type_task_name", type_task_name.gettext().tostring());     i.putextra("text_date", text_date.gettext().tostring());     i.putextra("seekbar", seekbar.getprogress());     setresult(result_ok, i);     finish(); } } 

you don't need data in onactivityresults because calles when returns activity if activity new in stack can it's bumndle data in oncreate method put follwing code-

newtask.java

public void buttonaddclick(view v) {      intent = new intent(newtask.this, mainactivity.class);     i.putextra("type_task_name", type_task_name.gettext().tostring());     i.putextra("text_date", text_date.gettext().tostring());     i.putextra("seekbar", seekbar.getprogress());     startactivity(i);  } 

in mainactivity.java

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // data activity called it.     bundle data = getintent().getextras();     if (data != null) {        string str = data.getstring("type_task_name");        string str1 = data.getstring("text_date");         int value = data.getint("seekbar");      }   // whatever want data 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -