我的适配器类:
private CheckFavourite checkFavourite;
private ItemCLickCallback itemCLickCallback;
public void setCheckFavourite(final CheckFavourite checkFavourite){
this.checkFavourite = checkFavourite;
}
public void setItemCLickCallback(final ItemCLickCallback itemCLickCallback){
this.itemCLickCallback = itemCLickCallback;
}
public interface ItemCLickCallback {
void onItemClick(int p);
void onSecItemClick(int p);
}
boolean isFavourite = checkFavourite.getFavourite(winkel);
public interface CheckFavourite{
boolean getFavourite(Winkel winkel);
}
片段:
public class Overview extends Fragment implements Adaptor.ItemCLickCallback{
adaptor = new Adaptor(mijnwinkels, this.getActivity());
adaptor.setItemCLickCallback(this);
// Code is incomplete, but this works.
adaptor.setCheckFavourite(this.getActivity());
// This doesn't work.
}
的活动:
public class SecondActivity extends AppCompatActivity implements Adaptor.CheckFavourite{
@Override
public boolean getFavourite(Winkel winkel){
boolean isFavourite = false;
MyDBHandler dbHandler = new MyDBHandler(this,null,null,1);
isFavourite = dbHandler.isFavourite(user,winkel);
return isFavourite;
}
}
我的片段实现了第一个接口,我的适配器在我的片段中创建。我的活动实现了第二个接口,因为我需要在我的活动中运行该函数的数据,但它是同一个适配器。我怎样才能让它发挥作用?这是我的错误:
Error:(60, 51) error: incompatible types: FragmentActivity cannot be converted to CheckFavourite.
不知怎的,它现在正在随机工作?我没有得到它,但我想它已经修好了。在代码开始工作的时候,我没有改变任何东西,哈哈。
答案 0 :(得分:1)
也许你只需要添加演员
adaptor.setCheckFavourite((Adaptor.CheckFavourite)this.getActivity());
答案 1 :(得分:0)
代码现在开始工作了。我没有改变任何东西,但它正在发挥作用。非常奇怪,但我想这毕竟不是一个好问题。我的借口。