EditInformation 扩展为片段。我在这一行得到错误
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
,错误的第一个参数类型。
public void RetrieveInformation(final String id)
{
class GetEmployee extends AsyncTask<Void,Void,String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
showEmployee(s);
}
@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequestParam(Config.RETRIEVE_INFORMATION,id);
return s;
}
}
GetEmployee ge = new GetEmployee();
ge.execute();
}
错误
Error:(124, 62) error: incompatible types: EditInformation cannot be converted to Context
我更改为EditInformation.getActivity(),但收到错误non-static method
答案 0 :(得分:3)
更改
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
到
loading = ProgressDialog.show(getActivity(),"Fetching...","Wait...",false,false);
由于您已经在Fragment
上下文中,getActivity()
可以解决问题。
答案 1 :(得分:1)
当你在一个片段中时,你不会通过说你的片段来获得上下文。要实现这一点,你可以使用getActivity()方法返回容器活动的上下文,你也可以说getActivity()。getApplicationContext()都可以正常工作。