0

Ich habe ein Fragment mit zu aktualisieren Pull. Alles funktioniert gut, wenn die Listenansicht keine Daten enthält, aber wenn es mindestens eine Zeile hat, reagiert es nicht, wenn ich es wische, um es zu aktualisieren. Hier ist das XML des Fragments:Swipe zu aktualisieren funktioniert nicht, wenn ich Daten in listView Android habe

<?xml version="1.0" encoding="utf-8"?> 
<share.advice.khalifa.adviceshare.view.ListFragmentSwipeRefreshLayout 
    android:id="@+id/going_out_activity_swipe_to_refresh" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clickable="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab_going_out" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentStart="true" 
      android:layout_margin="@dimen/fab_margin" 
      android:src="@drawable/ic_event"/> 


     <ListView 
      android:id="@+id/going_out_activity_list_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/layout_padding" 
      android:background="@drawable/transparentna" 
      android:scrollbarStyle="outsideOverlay" 
      android:scrollbars="none" 
      android:visibility="visible"/> 

    </RelativeLayout> 



</FrameLayout> 


</share.advice.khalifa.adviceshare.view.ListFragmentSwipeRefreshLayout> 

Und hier ist meine Gewohnheit ListFragmentSwipeRefreshLayout:

public class ListFragmentSwipeRefreshLayout extends SwipeRefreshLayout { 

private ListView mListView; 

public ListFragmentSwipeRefreshLayout(Context context) { 
    super(context); 
} 

public ListFragmentSwipeRefreshLayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public ListView getmListView() { 
    return mListView; 
} 

public void setmListView(ListView mListView) { 
    this.mListView = mListView; 
} 

/** 
* As mentioned above, we need to override this method to properly signal when a 
* 'swipe-to-refresh' is possible. 
* 
* @return true if the {@link android.widget.ListView} is visible and can scroll up. 
*/ 
@Override 
public boolean canChildScrollUp() { 
    final ListView listView = getmListView(); 
    if (listView.getVisibility() == View.VISIBLE) { 
     return canListViewScrollUp(listView); 
    } else { 
     return false; 
    } 
} 


/** 
* Utility method to check whether a {@link ListView} can scroll up from it's current position. 
* Handles platform version differences, providing backwards compatible functionality where 
* needed. 
*/ 
private static boolean canListViewScrollUp(ListView listView) { 
    if (android.os.Build.VERSION.SDK_INT >= 14) { 
     // For ICS and above we can call canScrollVertically() to determine this 
     return ViewCompat.canScrollVertically(listView, -1); 
    } else { 
     // Pre-ICS we need to manually check the first visible item and the child view's top 
     // value 
     return listView.getChildCount() > 0 && 
       (listView.getFirstVisiblePosition() > 0 
         || listView.getChildAt(0).getTop() < listView.getPaddingTop()); 
    } 
} 
} 

Und Fragment Code:

public class SuggestionGoingOutFragment extends Fragment implements ActivityAdapter.onContactsClickListener { 

    private Model mModel; 

    private OnActivityItemClicked mCallback; 

    public static ActivityAdapter mActivityAdapter; 

    private ListFragmentSwipeRefreshLayout mSwipeToRefresh; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.fragment_going_out, container, false); 

     mModel = Model.getInstance(getActivity()); 
     mSwipeToRefresh = (ListFragmentSwipeRefreshLayout) view.findViewById(R.id.going_out_activity_swipe_to_refresh); 
     mSwipeToRefresh.setmListView(((ListView) view.findViewById(R.id.going_out_activity_list_view))); 
     mSwipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
      @Override 
      public void onRefresh() { 
       mSwipeToRefresh.setRefreshing(true); 
       doUpdate(view); 
      } 
     }); 
     initView(view); 

     return view; 
    } 
    } 
+0

Coud Sie Ihre Fragment/Adapter-Code? –

+0

@JakubHolovsky hinzugefügt –

Antwort

1

Sie bieten didnt Details von dem, was in doUpdate geschieht (Blick), jedenfalls hier ist, was ich in onRefresh() getan habe.

@Override 
     public void onRefresh() { 

      refreshLayout.setRefreshing(true); 

// create a handler to run after some milli seconds 
// get data 
      new Handler().postDelayed(new Runnable() { 
       @Override 
       public void run() { 

        // call method for updated data for the list view 
        getlistviewdata(); 
// create new adapter with the new data 
        recyclerAdapter = new RecyclerAdapter(MainArrayList); 
     recyclerView.setAdapter(recyclerAdapter); 

        recyclerAdapter.notifyDataSetChanged(); 
        refreshLayout.setRefreshing(false); 
       } 
      }, 2000); 

     } 
Verwandte Themen