2014-02-19 141 views
0

我有兩個類,一個擴展了FragmentActivity,另一個擴展了Fragment將hashmap包傳遞給一個片段

我想將包中的哈希映射傳遞給FragmentActivity類中的片段類。 Fragment類應根據從FragmentActivity類收到的哈希映射值繪製圖(通過graphView庫),並且該圖將顯示在FragmentActivity xml文件的「片段」部分內。我想在Checkbox上調用Fragment類,即當檢查某個CheckBox時,應該將hashmap傳遞給Fragment類。下面是我的代碼,它不顯示任何錯誤,但它也不起作用。我嘗試了一個非常小的片段示例,該示例工作正常,但無法使其在我的實際應用程序中正常工作。我會很感激任何幫助。

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"); 

}

它甚至不顯示不依賴於包中的日誌信息。 非常感謝

回答

1

您創建了Fragment,但沒有用它做任何事情。您必須通過ActivityFragmentManager獲得FragmentTransaction,並適當添加新的Fragment

+0

謝謝拉里,我會盡力按照你的建議去做。 – user2387107