基本的に、Eclipse と Android 開発ツールが提供するデフォルトの新しいアクティビティ UI を、スクロール可能なタブとスワイプで構築しました。
Fragment
基づいています。
フラグメント内のビューを膨張させようとしています。このビューにボタン クリック リスナーをアタッチすると、AsyncTask が開始され、そのonPostExecute
メソッドに進行状況ダイアログが表示されます。
ここにいくつかのコードがあります:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_view, container, false);
Button bProcess= (Button) rootView.findViewById(R.id.bJustParked);
bProcess.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new JustParkedGetLocation().execute();
}
});
// Modify views in fragment below
return rootView;
}
明らかに、JustParkedGetLocation
AsyncTask を拡張し、onCreateView
上記のメソッドを保持するクラスのサブクラスです。ただし、たとえば、でダイアログを作成する場合JustParkedGetLocation->onPreExecute()
:
@Override
protected void onPreExecute() {
ProgressDialog progress = new ProgressDialog(this);
progress.setIndeterminate(true);
progress.setTitle("Getting location");
progress.show();
super.onPreExecute();
}
...メソッドを保持するクラスはデフォルトで静的 (を拡張するクラス) であるため、コンストラクターのパラメーターがProgressDialog
正しくありません。次のエラーが発生します。onCreateView
Fragment
The constructor ProgressDialog(MainActivity.ExtendedFragment.JustParkedGetLocation) is undefined