java - Can't get values passed through using Intent -


having trouble passing values 1 class another. have timetable class want send value class called daytab. value want pass through called day. i've attempted pass through using intent.putextra() it's either not sending value or not receiving it. it's supposed store received variable in string daynew in daytab.java

timetable.java:

 package day.tab;

import android.app.tabactivity;

import android.content.intent; import android.content.res.resources; import android.os.bundle; import android.widget.tabhost;

public class timetable extends tabactivity {

private static final string extra_day = "extra_day";   /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      resources res = getresources(); // resource object drawables     tabhost tabhost = gettabhost();  // activity tabhost     tabhost.tabspec spec;  // resusable tabspec each tab     intent intent;  // reusable intent each tab      // create intent launch activity tab (to reused)      intent = new intent().setclass(this, daytab.class);       // initialize tabspec each tab , add tabhost     spec = tabhost.newtabspec("monday").setindicator("mon",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);      intent.putextra(extra_day, "monday");     tabhost.addtab(spec);      // same other tabs     intent = new intent().setclass(this, daytab.class);     spec = tabhost.newtabspec("tuesday").setindicator("tue",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);     intent.putextra(extra_day, "tuesday");     tabhost.addtab(spec);      intent = new intent().setclass(this, daytab.class);     spec = tabhost.newtabspec("wednesday").setindicator("wed",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);     intent.putextra(extra_day, "wednesday");     tabhost.addtab(spec);      intent = new intent().setclass(this, daytab.class);     spec = tabhost.newtabspec("thursday").setindicator("thur",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);     intent.putextra(extra_day, "thursday");     tabhost.addtab(spec);      intent = new intent().setclass(this, daytab.class);     spec = tabhost.newtabspec("friday").setindicator("fri",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);     intent.putextra(extra_day, "friday");     tabhost.addtab(spec);      intent = new intent().setclass(this, daytab.class);     intent.putextra(extra_day, "saturday");     spec = tabhost.newtabspec("saturday").setindicator("sat",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);      tabhost.addtab(spec);      intent = new intent().setclass(this, daytab.class);     spec = tabhost.newtabspec("sunday").setindicator("sun",                       res.getdrawable(r.drawable.ic_tab_artists))                   .setcontent(intent);     intent.putextra(extra_day, "sunday");     tabhost.addtab(spec);      tabhost.setcurrenttab(0); } 

}

daytab.java.extra_day:

 package day.tab;

import android.app.listactivity; import android.content.intent; import android.database.cursor; import android.os.bundle; import android.view.contextmenu; import android.view.contextmenu.contextmenuinfo; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.adaptercontextmenuinfo; import android.widget.adapterview.onitemclicklistener; import android.widget.arrayadapter; import android.widget.listview; import android.widget.simplecursoradapter;

public class daytab extends listactivity {

private static final int activity_create=0; private static final int activity_edit=1;  private static final int insert_id = menu.first; private static final int delete_id = menu.first + 1;  private string daynew; private notesdbadapter mdbhelper;  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.notes_list);      daynew = getintent().getstringextra("extra_day");      mdbhelper = new notesdbadapter(this);     mdbhelper.open();     filldata();     registerforcontextmenu(getlistview());       string[] hour = getresources().getstringarray(r.array.hours);     setlistadapter(new arrayadapter<string>(this, r.layout.list_item, hour));     listview lv = getlistview();     lv.settextfilterenabled(true);     lv.setonitemclicklistener(new onitemclicklistener() {         public void onitemclick(adapterview<?> parent, view view,                 int position, long id) {                 mdbhelper.open();                 filldata();                 registerforcontextmenu(getlistview());         }     }); } /** called when activity first created. */ private void filldata() {     // of rows database , create item list     cursor notescursor = mdbhelper.fetchallnotes(daynew);     startmanagingcursor(notescursor);      // create array specify fields want display in list (only title)     string[] = new string[]{notesdbadapter.key_title};      // , array of fields want bind fields (in case text1)     int[] = new int[]{r.id.text1};      // create simple cursor adapter , set display     simplecursoradapter notes =          new simplecursoradapter(this, r.layout.notes_row, notescursor, from, to);     setlistadapter(notes); }  @override public boolean oncreateoptionsmenu(menu menu) {     super.oncreateoptionsmenu(menu);     menu.add(0, insert_id, 0, r.string.menu_insert);     return true; }  @override public boolean onmenuitemselected(int featureid, menuitem item) {     switch(item.getitemid()) {     case insert_id:         createnote();         return true;     }      return super.onmenuitemselected(featureid, item); }  @override public void oncreatecontextmenu(contextmenu menu, view v,         contextmenuinfo menuinfo) {     super.oncreatecontextmenu(menu, v, menuinfo);     menu.add(0, delete_id, 0, r.string.menu_delete); }  @override public boolean oncontextitemselected(menuitem item) {     switch(item.getitemid()) {     case delete_id:         adaptercontextmenuinfo info = (adaptercontextmenuinfo) item.getmenuinfo();         mdbhelper.deletenote(info.id);         filldata();         return true;     }     return super.oncontextitemselected(item); }  private void createnote() {     intent = new intent(this, noteedit.class);     startactivityforresult(i, activity_create); }  @override protected void onlistitemclick(listview l, view v, int position, long id) {     super.onlistitemclick(l, v, position, id);     intent = new intent(this, noteedit.class);     i.putextra(notesdbadapter.key_rowid, id);     startactivityforresult(i, activity_edit); }  @override protected void onactivityresult(int requestcode, int resultcode, intent intent) {     super.onactivityresult(requestcode, resultcode, intent);     filldata(); } 

}

androidmanifest.xml:

       

    <activity android:name=".timetable" android:label="@string/app_name"         android:theme="@android:style/theme.notitlebar">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>      <activity android:name=".noteedit"></activity>     <activity android:name=".daytab">         <intent-filter>             <action android:name="aexp.timetable.add"></action>             <category android:name="android.intent.category.launcher"></category>         </intent-filter> 


thanks in advance help!!

i don't see initialize string day?

side note - a) make name upper-case, because it's constant (extra_day, example), , b) mark static final.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -