我有一个使用以下代码
扩展SampleActivityBase的mainactivitypublic class MainActivity extends SampleActivityBase {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment();
transaction.replace(R.id.sample_content_fragment, fragment);
transaction.commit();
}
}
}
我有另一个班级
public class SlidingTabsBasicFragment extends Fragment {
在这个课程中我有另一个子类
class SamplePagerAdapter extends PagerAdapter {
在覆盖所有必要的功能后,我还有一个功能
public String getJSON(String url) {
class GetJSON extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(SlidingTabsBasicFragment.this.getContext(), "Please Wait...", "Checking", true, true);
}
@Override
protected String doInBackground(String... params) {
Log.d("doInBackground : ", "Function Started");
String uri = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(uri);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json + "\n");
}
jsonString = sb.toString().trim();
return sb.toString().trim();
} catch (Exception e) {
return new String("Exception: " + e.getMessage());
}
}
@Override
protected void onPostExecute(String s) {
if(loading.isShowing()) {
loading.dismiss();
}
super.onPostExecute(s);
jsonString = s;
}
}
GetJSON gj = new GetJSON();
gj.execute(url);
return jsonString;
}
当我在SamplePagerAdapter类中调用此函数时,除了Progress Dialog之外,每件事都可以正常工作。它没有显示......
请告诉我我做错了什么,如何显示进度对话框。选项卡显示来自在线数据库的数据,我希望在数据变胖时启动进度对话框。
答案 0 :(得分:0)
保持适配器类的单独尝试.get()instaed of .execute