Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3490488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:31:21+00:00 2026-05-18T11:31:21+00:00

Having some trouble passing values from one class to another. I basically have a

  • 0

Having some trouble passing values from one class to another. I basically have a Timetable class from which I want to send a value to another class called daytab.
The value I want to pass through is called day. I’ve attempted to pass it through using intent.putExtra() but it’s either not sending the value or not receiving it.
It’s supposed to store the received variable in the 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 the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)

    intent = new Intent().setClass(this, daytab.class);


    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("Monday").setIndicator("Mon",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);

    intent.putExtra(EXTRA_DAY, "monday");
    tabHost.addTab(spec);

    // Do the same for the 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 the activity is first created. */
private void fillData() {
    // Get all of the rows from the database and create the item list
    Cursor notesCursor = mDbHelper.fetchAllNotes(daynew);
    startManagingCursor(notesCursor);

    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{NotesDbAdapter.KEY_TITLE};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.text1};

    // Now create a simple cursor adapter and set it to 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 i = 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 i = 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 for any help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:31:22+00:00Added an answer on May 18, 2026 at 11:31 am

    I don’t see where you initialize the string day?

    Side note – I would a) make its name all upper-case, because it’s a constant (EXTRA_DAY, for example), and b) mark it static final.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.