我之前在片段上使用过这段代码,我想在Activity中使用这段代码,但是当getActivity()出现错误时 这是我的代码
final ListView listView = (ListView) rootView.findViewById(R.id.list);
adapter = new CustomListAdapter(getActivity(), exerciseList);
listView.setAdapter(adapter);
pDialog = new ProgressDialog(getActivity());
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
答案 0 :(得分:1)
getActivity()
上没有Activity
方法。将getActivity
替换为this
(或者,如果需要,TheNameOfYourActivityClass.this
,其中TheNameOfYourActivityClass
是您的活动类的名称。)
答案 1 :(得分:1)
将getActivity()
更改为this
或ActivityName.this
答案 2 :(得分:0)
getActivity method is not resolve in Activity.You can use getApplicationcontext.