我有一個活動,其中有一個ViewPager,在這個ViewPager中有一些片段。當屏幕上顯示數據時,我需要發送數據。所以我想在活動中實現一個將數據發送到片段的接口。通過監聽器從活動發送數據到片段
public interface SetDataToFragment {
void getData(List<FinanceOperationModel> aModels);
}
public class FinanceMonitoringActivity extends ApiActivity2 implements FinanceMonitoringView
, FinanceMonitoringFragment.SaveDataInterface {
private SetDataToFragment mInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finance_monitoring);
ButterKnife.bind(this);
mInterface= (SetDataToFragment) this;
...
然後有一個錯誤:
Caused by: java.lang.ClassCastException: com.akbars.bankok.screens.financeMonitoring.FinanceMonitoringActivity cannot be cast to com.akbars.bankok.screens.financeMonitoring.SetDataToFragment
如何正確啓動界面中的活性片段使用數據?
FinanceMonitoringActivity沒有實現SetDataToFragment – Pehlaj