我想在操作栏中显示和隐藏进度条。在这里,我使用SherlockListFragment扩展我的类,没有onCreate方法可用。我试过了this但没有奏效。我怎样才能做到这一点。
提前致谢..
这是我的代码:
package com.geeklabs.footmark.activity.tab;
import java.util.List;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.actionbarsherlock.app.SherlockListFragment;
import com.geeklabs.footmark.activity.tab.adapter.TrackAdapter;
import com.geeklabs.footmark.domain.Track;
import com.geeklabs.footmark.event.EndlessScrollListener;
import com.geeklabs.footmark.task.GetCapturedTracks;
public class CaptureListFragmentTab extends SherlockListFragment {
private TrackAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
// Get tracks if not showing on UI
if (adapter != null && adapter.getTracks().isEmpty()) {
getTracks();
getActivity().setProgressBarIndeterminateVisibility(false);
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
Log.i("Loading Tracks", "Loading your moments");
adapter = new TrackAdapter(getActivity());
setListAdapter(adapter);
// Listen for scroll change, Are we at the end of list view ?
EndlessScrollListener endlessScrollListener = new EndlessScrollListener(
0) {
@Override
protected void runTask(int currentPage) {
// get tracks in background async task
GetCapturedTracks getCapturedTracks = new GetCapturedTracks(currentPage, CaptureListFragmentTab.this.getActivity(), null) {
@Override
protected void updateUI(final List<Track> tracks) {
getActivity().runOnUiThread(new Runnable() {
public void run() {
// Notify adapter with new track list
if (adapter != null && tracks != null
&& !tracks.isEmpty()) {
adapter.setTracks(tracks);
adapter.notifyDataSetChanged();
getActivity().setProgressBarIndeterminateVisibility(false);
}
}
});
}
};
getCapturedTracks.execute();
getActivity().setProgressBarIndeterminateVisibility(true);
}
};
getListView().setOnScrollListener(endlessScrollListener);
}
private void getTracks() {
getActivity().setProgressBarIndeterminateVisibility(true);
// get tracks in background async task
GetCapturedTracks getCapturedTracks = new GetCapturedTracks(0,
this.getActivity(), null) {
@Override
protected void updateUI(final List<Track> tracks) {
getActivity().runOnUiThread(new Runnable() {
public void run() {
// Notify adapter with new track list
if (adapter != null && tracks != null && !tracks.isEmpty()) {
adapter.setTracks(tracks);
adapter.notifyDataSetChanged();
// getActivity().setProgressBarIndeterminateVisibility(false);
} else if (adapter != null && adapter.getTracks().isEmpty()) {
setEmptyText("Oops no moments captured yet ...");
}
}
});
}
};
getCapturedTracks.execute();
getActivity().setProgressBarIndeterminateVisibility(true);
}
}
答案 0 :(得分:1)
是的Fragment,没有onCreate()
方法。但您可以在onCreateView()
方法中编写相同的代码。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
....
....
}