2012-06-13 81 views
0

我們如何將數據從活動發送到片段?通過使用FragmentPagerAdapter將碎片配置爲有效。將數據從活動發送到片段

Registers mini。

+0

檢索數據試試:HTTP: //stackoverflow.com/questions/9343241/passing-data-between-a-fragment-and-its-container-activity –

回答

1
  • 您可以使用setArguments將包創建時傳遞給片段。
  • 您可以創建方法來設置Fragment類中的數據。
0

可以通過使用Bundle

從活動(或片段)發送數據執行此:

int a = 5; 

Bundle args = new Bundle(); 
args.putInt("INT_DATA_TAG", a); 

Fragment fragment = Fragment.newInstance(args); 
//Making fragment transaction 

在片段

int a; 
public static Fragment newInstance(Bundle args) { 
     a = args.getInt("INT_DATA_TAG"); //use a constant for the tag 
     return new Fragment(); 
} 
相關問題