活动中的getActivity警告

时间:2016-05-15 15:25:58

标签: android android-activity

我之前在片段上使用过这段代码,我想在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();

3 个答案:

答案 0 :(得分:1)

getActivity()上没有Activity方法。将getActivity替换为this(或者,如果需要,TheNameOfYourActivityClass.this,其中TheNameOfYourActivityClass是您的活动类的名称。)

答案 1 :(得分:1)

getActivity()更改为thisActivityName.this

答案 2 :(得分:0)

getActivity method is not resolve in Activity.You can use getApplicationcontext.