Having some problems 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 meaning I want to convey is called day. I tried passing it using intent.putExtra (), but it either did not send the value or did not receive it. It should store the resulting 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 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); }
}
code>
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()); } }); } private void fillData() {
}
code>
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 your help!