Reputation: 3
I have two classes, one extends FragmentActivity
and the other extends Fragment
.
I want to pass a hash map in a bundle to the Fragment class from the FragmentActivity
class. The Fragment
Class should draw a graph (through graphView library) based on the hash map values it receives from the FragmentActivity
class and that graph would be displayed inside the "fragment" part of the FragmentActivity
xml file. I want to invoke the Fragment
class on a Checkbox
i.e. A hashmap should be passed to the Fragment
class when a certain CheckBox
is checked. Below is my code which does not show any errors but it doesn't work either. I tried a very small fragment example, which worked but I cannot make it work in my actual application. I'd be grateful for any help.
public class Graphs_Combination extends FragmentActivity {
// some other code
public void onClick(View v)
{
Fragment fr;
fr = new DrawSingleGraph();
if (((CheckBox) v).isChecked())
{
ListOfCheckedFctrsNames.add(((CheckBox) v).getText().toString());
displayCheckedTextViews(ListOfCheckedFctrsNames);
Bundle bundle = new Bundle();
bundle.putSerializable(((CheckBox) v).getText().toString(),mMap);
fr.setArguments(bundle);
}
}
}
public class DrawSingleGraph extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.draw_single_graph,container, false);
Log.e(LOG, "Inside DrawSingleGraph");
Bundle b = this.getArguments();
if(b.getSerializable("Depression") != null)
mMap = (HashMap<String, HashMap<String,String>>)b.getSerializable("Depression");
}
It doesn't even show the Log message which doesn't depend on the bundle. Many Thanks
Upvotes: 0
Views: 1242
Reputation: 15775
You created your Fragment
, but didn't do anything with it beyond that. You have to get a FragmentTransaction
via the Activity
's FragmentManager
and add the new Fragment
appropriately.
Upvotes: 1