【问题标题】:Android Pull-to-Refresh with ListView Fragment & Custom ListView Adapter使用 ListView 片段和自定义 ListView 适配器的 Android 下拉刷新
【发布时间】:2014-04-27 21:25:48
【问题描述】:

我使用 Android Studio 启动选项构建了我的项目(使用选项卡自动构建 action bar),因此为我生成了一点。然而,我确实为每个使用自定义adapters 的选项卡实现了list-view fragment

我在从Chris Bane 添加下拉刷新库时遇到问题。也许我导入错了?我在 android 开发方面还很陌生,尤其是在这个新的 Gradle 方面。

我在这里在 build.gradle 文件中导入 github 存储库:

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion "19.0.1"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
  }
}
dependencies {
   compile 'com.android.support:support-v4:19.0.1'
   compile 'com.android.support:appcompat-v7:19.0.1'
   compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
 } 

所有减去 minSDKVersion 和依赖项的最后编译都是在我的项目创建时预先生成的。这个 build.gradle 文件是我的 `/app 文件夹中的那个。

Gradle 将正确同步,我将在项目根目录的 .idea 文件夹中看到来自操作栏 git 的文件。

这就是我感到困惑的地方:

在 github 存储库“快速启动”中它说

您需要做的第一件事是将可刷新视图包装在 PullToRefreshLayout 中:

通过代码示例执行如下操作:

<uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshLayout>
<listview/>
</uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshLayout>

uk.co.senab.actionbarpulltorefresh.extras 假设是我的项目名称,所以com.lucaapp.app

这是我的 ListFragment 的 XML,您会在其中看到我的困惑:

<?xml version="1.0" encoding="utf-8"?>

<com.lucaapp.app.PullToRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ptr_layout" >


<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#b5b5b5"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector" />


<TextView
    android:id="@android:id/empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="No Events" />

</com.lucaapp.app.PullToRefreshLayout>

在我尝试在我的片段类中实现来自quick start guide 的代码之前,这不会立即给我任何错误。我在尝试导入该 github 存储库方法时收到 Cannot Resolve Symbol 错误。

我已经尝试了以下方法,导致导入为红色并出现cannot resolve symbol 错误:

import com.lucapp.app.PullToRefreshAttacher;
import com.lucapp.app.PullToRefreshLayout;
import uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshAttacher;

【问题讨论】:

  • 为什么在使用 minsdk=14 时使用 compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'?使用:编译'com.github.chrisbanes.actionbarpulltorefresh:library:+'

标签: android listview android-fragments android-listfragment pull-to-refresh


【解决方案1】:

现在 android 引入了新的简单功能,称为 Swipe 以刷新布局。请参考网站devloper sitesimple example

【讨论】:

    【解决方案2】:

    您是否尝试过遵循 Chris Banes 的本教程: https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-ABS ?

    本教程包含所有步骤,从 build.gradle 开始,以代码 sn-ps 结束。

    唯一的区别:教程适用于 ScrollView(不是您希望的 ListView)。但不要害怕。只需将 ScrollView 替换为 ListView 就可以了。

    更新: 你应该特别看到这个块:

    <uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ptr_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <!-- Your content, here we're using a ScrollView -->
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
        </ScrollView>
    
    </uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout>
    

    您不应使用com.lucaapp.app.PullToRefreshLayout 代替uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多