我正在使用viewpager並創建片段,並且想要傳遞數組列表。所以我曾嘗試下面的事情:如何將自定義對象數組列表從實例傳遞到片段
MainActivity:
private ArrayList<customers> mArrayList = null;
ViewPagerAdapter adapter = new ViewPagerAdapter(MainActivity.this.getSupportFragmentManager());
adapter.addFrag(NewCustomer.newInstance(mArrayList), "NewCustomer");
現在片段類我創建實例:
public static final ArrayList<customers> data = new ArrayList<customers>();
public static final NewCustomer newInstance(ArrayList<customers> mArrayList) {
NewCustomer f = new NewCustomer();
Bundle bdl = new Bundle(1);
bdl.putParcelableArrayList(data, mArrayList);
f.setArguments(bdl);
return f;
}
但是,這是行不通的。它在bdl.putParcelableArrayList上顯示錯誤我想要獲取數組列表並將其存儲到該類的本地數組列表中。
如何獲取我的自定義對象的數組列表?
你應該解釋爲什麼你提供的代碼正在工作,它在做什麼。如果您僅提供一個代碼,這將不會幫助OP和下列可能最終出現類似問題的用戶。 – AxelH
@AxelH,是的,你說得對,我爲此道歉。 –
不要道歉;)但你如何解釋靜態上下文中'this'的用法?我真的沒有那個部分。或者該方法的錯誤用法;) – AxelH