我正在尝试使用SwipeRefreshLayout
但是当我在活动的OnRefreshListener
方法中设置onCreate()
时,滑动时不会调用它。查看示例代码,这似乎是正确的做事方式。当我稍后注册听众时,例如在onPostCreate()
或按下按钮时,它会在刷卡时被调用。我错过了什么?
MessageListActivity.java :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_list);
final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.d(TAG, "Swiped for refresh!");
}
});
}
activity_message_list.xml :
<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".LoginActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_layout">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
android:drawSelectorOnTop="false">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
答案 0 :(得分:0)
原来我犯了一个相当愚蠢的错误。我在onCreate之后的某个地方调用了setContentView(R.layout.activity_message_list),导致资源再次膨胀。