android - 从 Activity 到 Fragment:IonWrapper 错误
问题描述
当我要将 Activity 转换为片段时遇到 IonWrapper 问题:
IonWrapper 中的 IonWrapper (Context, com.codingvisions.chat_fcm.helper.IonWrapper.WebServiceInterFace) 无法应用于 (FragmentActivity, android.support.v4.app.FragmentActivity)
我尝试在 IonWrapper 中两次传递 getActivity。
/* Original function Activity */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_richiesta_invio_pacco);
customAlertDialog = new CustomAlertDialog(this);
sharedPrefsHelper = new SharedPrefsHelper(this);
webServices = new WebServices(this, new IonWrapper(this, this));
sqliteDbManager = new SqliteDbManager(this);
DataPartenzaInput = (TextInputEditText)findViewById(R.id.data_partenza_pacco);
DimensioniInput = (TextInputEditText)findViewById(R.id.dimensioni_input);
VaiButton = (Button)findViewById(R.id.vai_button);
}
/* Function in Fragment */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_richiesta_pacco, container, false);
/* .... */
customAlertDialog = new CustomAlertDialog(getActivity());
sharedPrefsHelper = new SharedPrefsHelper(getActivity());
webServices = new WebServices(this, new IonWrapper(getActivity(), getActivity()));
sqliteDbManager = new SqliteDbManager(getActivity());
/* ....*/
/* Constructor IonWrapper
public IonWrapper(Context context, WebServiceInterFace webServiceInterFace) {
this.context = context;
this.webServiceInterFace = webServiceInterFace;
}
*/
}
解决方案
在活动和片段中实现 com.codingvisions.chat_fcm.helper.IonWrapper.WebServiceInterFace。然后在片段中初始化时将此作为第二个参数传递。
推荐阅读
- elasticsearch - 在弹性搜索中更新嵌套对象
- java - Android Google Map SDK - 仅在应用程序通过 adb 启动时工作
- kubernetes - 如何更改 kubernetes pod 中的 cassandra.yaml?
- swift - 单击按钮更改视图控制器背景颜色
- mysql - MySQL检查是否采用日期间隔
- javascript - 带有内部 React 的 Spring Boot - 以正确的方式传递 ENV
- c - 逐渐重新分配内存会导致分段错误
- python - Django,如何根据另一个表单过滤表单
- java - Pageable 的自定义实现
- google-maps - Android Auto 防止变暗