Ma question est exactement comme celle-ci.Viewpager avec SwipeRefreshLayout quand rafraîchir l'icône ne disparaît pas
Frozen snapshot of list rendered with SwipeRefreshLayout in ViewPager
Mais bref, j'actualiser la liste et la chose de filature permet de rester toujours en cours après que la liste a été actualisée.
J'ai essayé la solution suivante qu'il a donnée de l'emballage du SwipeRefreshLayout avec un FrameLayout et je n'ai pas eu de succès.
Voici des captures d'écran de ce que j'ai en ce moment, et le code dans lequel je l'implémente.
Dans ma classe Fragment et parties de mon AsyncTask,
private LocationUtil loc;
private static final String ARG_SORT_TYPE = "sortType";
String sortType = null;
private ArrayList<Facility> results;
private SwipeRefreshLayout mPtrListView;
private ListView waitTimesListView;
SummaryAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_wait_times_viewpager_fragment,container,false);
mPtrListView = (SwipeRefreshLayout) view.findViewById(R.id.wait_times_pull_refresh_list);
waitTimesListView = (ListView) view.findViewById(R.id.wait_times_listview);
waitTimesListView.setOnItemClickListener(this);
mPtrListView.setOnRefreshListener(this);
WaitTimesTask task = new WaitTimesTask(getActivity());
task.execute(sortType, longitudeLocation, latitudeLocation);
return view;
}
@Override
public void onRefresh() {
WaitTimesTask task = new WaitTimesTask(getActivity());
task.execute("name", longitudeLocation, latitudeLocation);
}
public void setLocation(){
if(loc.useSmartLocation()){
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
Log.v("Check Location frag" + sortType + " " , " " + location.getLongitude() + " " + location.getLatitude());
latitudeLocation = Double.toString(location.getLatitude());
longitudeLocation = Double.toString(location.getLongitude());
} else {
Log.v("Check waitTimesActivity" , " is null");
}
}
else {
loc.determineLocation();
latitudeLocation = Double.toString(loc.getLatitude());
longitudeLocation = Double.toString(loc.getLongitude());
}
}
@Override
protected void onPreExecute() {
dialog = AsyncProgressDialog.show(mContext, "", "");
setLocation();
}
@Override
protected void onPostExecute(String string) {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
if(string != null){
Log.v("result on post & type: " + Sort, string);
NovantFacilityXmlParser parser = new NovantFacilityXmlParser();
string = string.replace("&", "&");
try {
results = parser.parse(new ByteArrayInputStream(string.getBytes()));
} catch (IOException | XmlPullParserException ex) {
Log.e("Parsing error:", ex.getMessage());
}
Log.v("SetUp "," of List");
if(!results.isEmpty()) {
adapter = new SummaryAdapter(mContext, R.layout.row_wait_time, results.toArray(new Facility[results.size()]));
waitTimesListView.setAdapter(adapter);
}
}
else{
Toast.makeText(getActivity(), "No data available", Toast.LENGTH_LONG).show();
}
}
Mon xml, les éclats et l'activité principale.
Activité xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/aubergine">
<android.support.design.widget.TabLayout
android:id="@+id/wait_times_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="3dp"
app:tabIndicatorColor="#ffffff"
app:tabSelectedTextColor="#ffffff"
app:tabMode="fixed"
android:background="#333333"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/wait_times_ViewPager">
</android.support.v4.view.ViewPager>
</LinearLayout>
Fragment xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/base_color">
<!--tools:context=".WaitTimesFragment">-->
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/wait_times_pull_refresh_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/wait_times_listview"/>
</android.support.v4.widget.SwipeRefreshLayout>
<include layout="@layout/novant_menu_layout" />
Dans mon OnpostExecute, je reçois la chaîne du doinBackground et analyser le flux xml et faire un arraylist que j'utilise pour mon adaptateur que j'ai fait sur mesure.
Toute aide serait grandement appréciée. Merci.
je suis confronté à la même question. Voulez-vous s'il vous plaît suggérer une solution? –
La solution ci-dessous a fonctionné pour moi. Sur le post, procédez comme suit, mPtrListView.setRefreshing (false). Mais comme vous pouvez le voir, j'utilise aussi un ProgressDialog dans AsyncTask. J'ai utilisé un booléen que j'ai défini sur true dans le onRefresh. J'ai ensuite utilisé ce booléen pour déterminer si je devrais montrer le ProgressDialog à chaque fois que l'utilisateur se rafraîchit, dans lequel je ne vais pas montrer si elles sont rafraîchissantes. @AdeelTurk – huey77