Android的上拉,以刷新与ListView的片段放;自定义的ListView适配器 [英] Android Pull-to-Refresh with ListView Fragment & Custom ListView Adapter

查看:186
本文介绍了Android的上拉,以刷新与ListView的片段放;自定义的ListView适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用的是Android Studio的启动选项构建我的项目(​​自动生成的操作栏的标签),所以对我产生了一点。然而,我却实现对标签中的每一个列表视图片段使用自定义适配器

I built my project using the Android Studio start options (Automatically builds the action bar with the tabs) so a bit is generated for me. I did however implement a list-view fragment for each one of the tabs that uses custom adapters.

我有一个麻烦来自克里斯贝恩。也许我输入错了?我是相当新的android开发,特别是与这种新的摇篮东西。

I'm having a trouble adding the pull-to-refresh lib from Chris Bane. Maybe I'm importing it wrong? I'm fairly new at android development and especially with this new Gradle stuff.

我导入GitHub的信息库中的build.gradle文件位置:

I'm Importing the github repository in the build.gradle file here:

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&放大器;在依赖过去的编译是pre-生成我的项目创建时。这的build.gradle文件是一个在我的`/ app文件夹。

Everything minus the minSDKVersion & the last compile in dependencies was pre-generated when my project was created. This build.gradle file is the one in my `/app folder.

摇篮会正常同步,我会在项目的根看到我.idea文件夹从动作条git的文件。

Gradle will sync properly and I will see files from the actionbar git in my .idea folder in the project root.

这里是我越来越糊涂:

在GitHub的回购快速启动它说。

In the github repo "quick start" it says

您需要做的是包装你的看法刷新在PullToRefreshLayout的第一件事情:

The first thing you need to do is wrap your refreshable view in a PullToRefreshLayout:

随着code例如做这样的事情:

With a code example doing something like this:

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

uk.co.senab.actionbarpulltorefresh.extras 假设是我的项目的名字,所以 com.lucaapp.app <​​/ code>

Is uk.co.senab.actionbarpulltorefresh.extras suppose to be my projects name, so com.lucaapp.app?

下面是我的XML我ListFragment,日子会把你在哪里看到我的困惑:

Here is my XML for my ListFragment, where u'll see my confusion:

<?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>

这不会立即给我任何错误,直到我试图实现从快速入门指南在我的片段类code。我得到一个无法解析符号错误尝试导入的github回购的方法。

This will not give me any errors immediately until I try to implement the code from the quick start guide in my fragment class. I get an Cannot Resolve Symbol error trying to import that github repo methods.

我已经试过这使得进口红色无法解析符号以下错误:

I've tried the following which makes the import red with cannot resolve symbol error:

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

我认为我有问题的只是我缺少进口图书馆的知识(从来没有这样做),所以请与我裸露,如果这是一个明显的修复。希望我提供足够的信息来帮助解决这个问题。

I assume the issues I'm having is just me lacking the knowledge of importing libraries (Never done it before) so please bare with me if this is an obvious fix. Hope I provided enough information to help resolve this.

推荐答案

你试过跟随克里斯巴内斯本教程:
https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-ABS

Have you tried to follow this tutorial from Chris Banes: https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-ABS ?

本教程包含所有步骤,从开始的build.gradle和code段完成。

This tutorial contains all steps, beginning from build.gradle and finishing with code snippets.

唯一的区别:教程是滚动型(不ListView控件如你所愿)。但是,不要害怕。只是替代的ListView滚动型,一切都应该确定。

The only difference: tutorial is for ScrollView (not ListView as you wish). But don't be scared. Just replace ScrollView with ListView and everything should be OK.

更新:

<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

这篇关于Android的上拉,以刷新与ListView的片段放;自定义的ListView适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆