First of all let me say I hope everybody on the East Coast is okay after Hurricane Sandy. I was lucky in that, although I live in New York City, I never even lost power. My thoughts go out to those of you who weren't as fortunate. Now that I'm back to work after three days, I need some help with fragments. I'm trying to pass a Bundle to a Fragment and it's not working. I know I've got the general fragment setup correct, because if I don't try to pass a Bundle, it works fine. So here's my Activity where I pass the Bundle:
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent choice = new Intent(getApplicationContext(), com.MyProject.project.MyList.class);
Bundle dataBundle = new Bundle();
String chosenValue = values[position];
dataBundle.putString("Level",chosenValue);
choice.putExtras(dataBundle);
startActivity(choice); }
Now here's my activity without the Bundle. This works fine:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] values = new String[] { "Enterprise", "Star Trek", "Next Generation", "Deep Space 9", "Voyager"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
However, when I try to get info from the Bundle, it doesn't work. Here's my code:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle info = getArguments();
String level = info.getString("level");
String[] values = new String[] {level, level};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
When I run this and click on my choice in my Activity, the app just hangs. LogCat doesn't seem to give me much info on this. Does anyone see any problem here?
Thanks!