Android SwipeRefreshLayout出现错误,无法在第一次刷新(加载更多)
我试图在我的应用程序中实现“滑动以加载更多”方法,但我在第一次向下滑动时遇到了这个错误。这是它在控制台中显示的内容: E/SwipeRefreshLayout:已获取操作\u移动事件,但没有活动的 指针id.E/SwipeRefreshLayout:获得了操作\u移动事件,但没有 活动指针id.E/SwipeRefreshLayout:已获取操作\u移动事件,但 没有活动的指针id。E/SwipeRefreshLayout:获得操作\u移动 事件,但没有活动指针id 这是我的布局代码:Android SwipeRefreshLayout出现错误,无法在第一次刷新(加载更多),android,swiperefreshlayout,Android,Swiperefreshlayout,我试图在我的应用程序中实现“滑动以加载更多”方法,但我在第一次向下滑动时遇到了这个错误。这是它在控制台中显示的内容: E/SwipeRefreshLayout:已获取操作\u移动事件,但没有活动的 指针id.E/SwipeRefreshLayout:获得了操作\u移动事件,但没有 活动指针id.E/SwipeRefreshLayout:已获取操作\u移动事件,但 没有活动的指针id。E/SwipeRefreshLayout:获得操作\u移动 事件,但没有活动指针id 这是我的布局代码: <
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="training.com.chatgcmapplication.ChatActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="380dp">
<ListView
android:id="@+id/listMessage"
android:layout_width="match_parent"
android:layout_height="380dp"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:divider="@null"
android:listSelector="@android:color/transparent"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<EditText
android:id="@+id/txt_chat"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.92"
android:inputType="text" />
<Button
android:id="@+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:text="@string/btn_send" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
我用此代码替换该代码,但仍然存在相同的问题:
lv_message.post(new Runnable() {
@Override
public void run() {
lv_message.setSelection(lv_message.getCount() -1);
}
});
我认为问题在于,您试图在同一方法内显示、取消和刷新swipeRefreshLayout,即
onRefresh()
。
制作显示和取消对话框的单独方法,并从需要它们的地方调用它们,正如我在下面所做的:
@Override
public void onRefresh() {
// refresh code here.
}
@Override
public void showDialog() {
swipeRef.post(new Runnable() {
@Override
public void run() {
if(swipeRef != null)
swipeRef.setRefreshing(true);
}
});
}
@Override
public void dismissDialog() {
if(swipeRef!=null && swipeRef.isShown() )
swipeRef.setRefreshing(false);
}
您可以添加实现此方法的活动,以及完整的日志猫吗?我刚刚添加了实现方法的活动和日志猫:它多次显示该错误。有解决此问题的方法吗(我已经实现了OnRefreshListener接口,但无法覆盖showDialog()和dismissDialog()。您确定它属于该接口吗?我可以将两个dialog方法放入onRefresh()中吗)方法?实际上,我有一个单独的接口,它从SwiperFreshLayout扩展了OnRefreshListener接口,我在那里定义了show dialog和dismissdialog方法。您当前的活动实现了这个单独的接口。这些被重写的方法就是从那里来的。这是我工作区中的一个片段。将两个dialog方法放在onRefresh()中不起作用?嗯,那么我猜代码有问题。你应该包括整个日志cat错误!其他人可能会觉得这很有帮助
lv_message.post(new Runnable() {
@Override
public void run() {
lv_message.setSelection(lv_message.getCount() -1);
}
});
@Override
public void onRefresh() {
// refresh code here.
}
@Override
public void showDialog() {
swipeRef.post(new Runnable() {
@Override
public void run() {
if(swipeRef != null)
swipeRef.setRefreshing(true);
}
});
}
@Override
public void dismissDialog() {
if(swipeRef!=null && swipeRef.isShown() )
swipeRef.setRefreshing(false);
}