【问题标题】:Android Studio Swipe RefreshAndroid Studio 滑动刷新
【发布时间】:2017-02-03 22:58:15
【问题描述】:

只是想知道是否有人可以帮助我,我正在尝试添加滑动刷新功能,但我看不到哪里出错了,我只是收到错误消息无法解析符号 mySwipeRefreshLayout

这是代码。谢谢

public class eventsListActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {

mySwipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {

        refreshList();
    }
}

public class eventsListActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {

mySwipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {

        refreshList();
    }
}

XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_events_list"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.parse.fypPlannr.eventsListActivity"
  android:background="#24B14D">

 <android.support.v4.widget.SwipeRefreshLayout
   android:id="@+id/Swiper"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
<ListView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_centerHorizontal="true"
   android:id="@+id/eventList"
   android:layout_below="@+id/createEvent"
   android:textColor="@android:color/holo_orange_light"/>
</android.support.v4.widget.SwipeRefreshLayout>
<Button
   android:text="Map View"
   android:layout_height="wrap_content"
   android:id="@+id/mapButton"
   android:layout_width="wrap_content"
   android:layout_alignParentTop="true"
   android:layout_centerHorizontal="true"
   android:background="#029789"
   android:textColor="#ffffbb33"
   android:onClick="mapView" />

<Button
   android:text="Log Out"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/logOut"
   android:onClick="logOut"
   android:background="#029789"
   android:textColor="#ffffbb33"
   android:layout_alignParentTop="true"
   android:layout_alignParentLeft="true"
   android:layout_alignParentStart="true"
   android:layout_toLeftOf="@+id/mapButton"
   android:layout_toStartOf="@+id/mapButton" />

<Button
   android:text="Create Event"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/createEvent"
   android:onClick="createEvent"
   android:background="#04988a"
   android:textColor="#ffffbb33"
   android:layout_alignParentTop="true"
   android:layout_toRightOf="@+id/mapButton"
   android:layout_alignParentRight="true"
   android:layout_alignParentEnd="true" />

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_events_list"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.parse.fypPlannr.eventsListActivity"
  android:background="#24B14D">

 <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/Swiper"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:id="@+id/eventList"
    android:layout_below="@+id/createEvent"
    android:textColor="@android:color/holo_orange_light"/>
</android.support.v4.widget.SwipeRefreshLayout>
<Button
    android:text="Map View"
    android:layout_height="wrap_content"
    android:id="@+id/mapButton"
    android:layout_width="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="#029789"
    android:textColor="#ffffbb33"
    android:onClick="mapView" />

<Button
    android:text="Log Out"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/logOut"
    android:onClick="logOut"
    android:background="#029789"
    android:textColor="#ffffbb33"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_toLeftOf="@+id/mapButton"
    android:layout_toStartOf="@+id/mapButton" />

<Button
    android:text="Create Event"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/createEvent"
    android:onClick="createEvent"
    android:background="#04988a"
    android:textColor="#ffffbb33"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/mapButton"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

http://pastebin.com/u72WtQ3y​ Java代码

http://pastebin.com/9KnYhJLp Xml​

【问题讨论】:

  • 我已经编辑了你的帖子,它会暂时可见。我已经在你的帖子中发布了代码。确保您对代码进行了更好的解释并发布了您的 logcat,您可以删除那些指向 stackoverflow 之外的一些网站的链接。
  • 使用前需要在Java中声明一个变量。您的 mySwipeRefreshLayout 尚未在当前类或任何超类中声明。在尝试 Android 之前,请花一些时间通过Java Tutorials 工作,否则从现在开始您将到处遇到难题。

标签: java android refresh swipe


【解决方案1】:

您不需要使用工具 SwipeRefreshLayout.OnRefreshListener。

我还没有发现其他问题。也许 refreshList() 中有错误;方法

【讨论】:

    猜你喜欢
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多