GVKun编程网logo

Chris Banes实现ActionBar-PulltoRefresh,库错误等

17

如果您想了解ChrisBanes实现ActionBar-PulltoRefresh,库错误等的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析actionbarsherlockgetSuppor

如果您想了解Chris Banes实现ActionBar-PulltoRefresh,库错误等的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok、ADChromePullToRefresh iOS 下拉刷新、android ActionBar-PullToRefresh 下拉刷新的使用方法、android – ActionBar – PullToRefresh的各个方面,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

Chris Banes实现ActionBar-PulltoRefresh,库错误等

Chris Banes实现ActionBar-PulltoRefresh,库错误等

与目前使用Chris Banes的ActionBar-
PullToRefresh的Google保持一致:https : //github.com/chrisbanes/ActionBar-
PullToRefresh,我决定我也想将该库用于我当前正在开发的Android应用程序我的实习。但是,当我尝试从解压缩的zip文件中将现有代码导入工作区时,在库以及示例活动中,我都会立即出现大量错误。例如,在库文件夹中的ActionBarPullToRefresh.java中,它在第一个私有哈希图中加了下划线,并表示应参数化对通用类型Class的引用。

IDE(eclipse)还会给包含的其他文件夹带来大量错误,当我使用属性->
android选项卡将库文件夹添加到主项目的库中时,它会将错误转移到该项目中(逻辑上相当)。

有人可以指导我如何成功导入和使用该库吗?

答案1

小编典典

我将在这里为将来的PullToRefresh用户编写此代码。我使用IntelliJ
IDEA而不是eclipse,因此请记住, 模块项目
一词是等效的。当您必须将项目添加到Eclipse时,操作是在IDEA中 添加模块

ActionBarSherlock(现在为ABS)的示例。

你所拥有的

  1. 您有一个名为:MyProject 的 模块 。这是您的主要Android模块。
  2. 您要在MyProject中将PullToRefresh添加到一些片段(例如)。

第一步 :下载并复制。

我个人比较喜欢读取或修改日志时使用的库的克隆或分支。您不仅可以通过查看其他人的代码来学习,而且还可以获得有关所用库的“最新消息”。这是双赢的局面。记住杰夫·阿特伍德(Jeff
Atwood)所说的话:“ 读源代码,卢克
”。因此,为了执行此操作,请从正确的URL克隆ActionBar-PullToRefresh 。

现在,我不喜欢将克隆与模块/项目一起使用,因此通常将项目克隆到其他位置,然后手动移动所需的内容。这很乏味,但是那样我只会得到我想要的。那么,您需要什么呢?该克隆包含两个重要目录:
ExtrasLibrary 。我们将需要这些东西。

将库目录复制到您的项目根目录:/path/to/your/project/pulltorefresh
将相应的(ABS或Compat)多余的内容也复制到您的项目根目录中…

到目前为止,这是您得到的:

/path/to/your/project/MyProject/path/to/your/project/pulltorefresh/path/to/your/project/pulltorefresh-abs (or compat)

第二步
导入这些模块:将这些模块(eclipse中的项目)导入到项目/工作区中。如果您了解您的IDE,这应该很简单,但可以作为快速参考:文件->导入模块->从上方找到pulltorefresh文件夹(以及以后的-
abs或compat)并按照向导进行操作。

现在您应该在左面板(⌘1)中具有以下结构

MyProjectpulltorefreshpulltorefresh-abs

步骤3 添加正确的参考

假设MyProjectactiobnarsherlock.jar(因为您需要)或相应的android支持库,compat并且您也有相应的android-support-v13(或v4)…

  1. pulltorefresh 不需要任何库引用。
  2. pulltorefresh-ABS 需要的引用:pulltorefreshandroid-suppport-vXactiobbarsherlock
  3. MyProject的 需要的引用:pulltorefresh-absandroid-suport-vXactiobbarsherlock

当然,android-
support和actiobarsherlock都可以位于MyProject中,并由其他库导出(并从那里取出),但这就是项目管理101;)

步骤4 整合!这很容易,只需遵循快速入门指南。 记住 :在旧版本的lib,你 必须
有一个活动的附加器,即不再是必要的。阅读文档,它非常简单(这种方式更加灵活)。

等待,如果您不使用Sherlock或Compat怎么办?

我还没有这样做,但是我的猜测是:

  1. 不要在中导入-abs或-compat extras。只需导入pulltorefresh
  2. 在您的项目中,参考pulltorefresh

等等…进口呢?

对于任何库来说,正确导入都是很重要的,您必须注意而不是盲目地让您的IDE为您做这件事(或者至少总是仔细检查您要导入的内容)。您会惊讶地发现那里有多少“名称冲突”。

对于基于Action Bar Sherlock的项目,导入应为:

import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout;import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;

对于 非夏洛克 纯项目:

import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;

你从哪儿得到的?!?!!?!?!

通过查看样本,卢克。

例如,这里是库存版本的。

最后一步是获利……但我把这留给您;)

如果您仍然有问题,则只要您不问懒惰的问题,他们都很友好。随时关注该项目,并参与github上的问题页面。

祝你好运令人耳目一新!

actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok

actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok

转载地址:http://stackoverflow.com/questions/11944855/actionbarsherlock-getsupportactionbar-return-null-in-android4-0-but-in-2-3-3-i


不想看那么多 E 文的:我直接说关键部分

找到





改完就可以了!

ADChromePullToRefresh iOS 下拉刷新

ADChromePullToRefresh iOS 下拉刷新

ADChromePullToRefresh 介绍

ADChromePullToRefresh 提供可自定义下拉刷新的功能。

ADChromePullToRefresh 官网

https://github.com/Antondomashnev/ADChromePullToRefresh

android ActionBar-PullToRefresh 下拉刷新的使用方法

android ActionBar-PullToRefresh 下拉刷新的使用方法

这个最终效果,  图片来自http://a.code4app.com/android/ActionBar-PullToRefresh/524f9a156803faab3c000000

由于对于导包不是很了解,这个下拉刷新花费了我很多时间。

其实很简单,也就是两个类,首先你要下载ActionBar-PullToRefresh    点击打开链接

然后还要下载  ActionBarSherlock   点击打开链接


然后打开ActionBar-PullToRefresh  下的项目  :  C:\Users\Administrator\Desktop\ActionBar-PullToRefresh-master\ActionBar-PullToRefresh-master\samples\stock


不过同时,你要先把ActionBarSherlock导入到ActionBar-PullToRefresh的根目录


那下面就好做了

[java]
/* 
 * Copyright 2013 Chris Banes 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */  
  
package uk.co.senab.actionbarpulltorefresh.samples.stock;  
  
import android.app.ListActivity;  
import android.os.AsyncTask;  
import android.os.Bundle;  
import android.view.View;  
import android.widget.ArrayAdapter;  
import android.widget.ListAdapter;  
import android.widget.ListView;  
  
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher;  
  
/** 
 * This sample shows how to use ActionBar-PullToRefresh with a 
 * {@link android.widget.ListView ListView}, and manually creating (and attaching) a 
 * {@link PullToRefreshAttacher} to the view. 
 */  
public class ListViewActivity extends ListActivity  
        implements PullToRefreshAttacher.OnRefreshListener {  
  
    private static String[] ITEMS = {"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",  
            "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega''l Pitu",  
            "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Abbaye de Belloc",  
            "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost",  
            "Affidelice au Chablis", "Afuega''l Pitu", "Airag", "Airedale", "Aisy Cendre",  
            "Allgauer Emmentaler"};  
  
    private PullToRefreshAttacher mPullToRefreshAttacher;  
  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
  
        /** 
         * Get ListView and give it an adapter to display the sample items 
         */  
        ListView listView = getListView();  
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,  
                ITEMS);  
        listView.setAdapter(adapter);  
  
        /** 
         * Here we create a PullToRefreshAttacher manually without an Options instance. 
         * PullToRefreshAttacher will manually create one using default values. 
         */  
        mPullToRefreshAttacher = new PullToRefreshAttacher(this);  
  
        // Set the Refreshable View to be the ListView and the refresh listener to be this.  
        mPullToRefreshAttacher.setRefreshableView(listView, this);  
    }  
  
    @Override  
    public void onRefreshStarted(View view) {  
        /** 
         * Simulate Refresh with 4 seconds sleep 
         */  
        new AsyncTask<Void, Void, Void>() {  
  
            @Override  
            protected Void doInBackground(Void... params) {  
                try {  
                    Thread.sleep(4000);  
                } catch (InterruptedException e) {  
                    e.printStackTrace();  
                }  
                return null;  
            }  
  
            @Override  
            protected void onPostExecute(Void result) {  
                super.onPostExecute(result);  
  
                // Notify PullToRefreshAttacher that the refresh has finished  
                mPullToRefreshAttacher.setRefreshComplete();  
            }  
        }.execute();  
    }  
}



这是下拉刷新的一个类   

android – ActionBar – PullToRefresh

android – ActionBar – PullToRefresh

我正在开发一个应用程序,您可以在其中查看Busstop时间表.用户可以使用ActionBar PullToRefresh(库)进行刷新.我的应用程序还启用了KitKat上的半透明状态栏.

现在ActionBar Overlay(通常应该与动作栏重叠)现在向上移位.

我怎么解决这个问题?

最好的祝福!

解决方法

我所做的是为pull-to-refresh布局创建自定义标题布局.我只是复制了原来的一个,添加了状态栏的高度,通常为25dp,并添加了25dp的顶部填充.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="73dp"
    android:paddingTop="25dp" >

    <FrameLayout
        android:id="@id/ptr_content"
        android:layout_width="match_parent"
        android:layout_height="73dp" >

        <TextView
            android:id="@id/ptr_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </FrameLayout>

    <fr.castorflex.android.smoothprogressbar.SmoothProgressBar
        android:id="@id/ptr_progress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="@dimen/ptr_progress_bar_stroke_width" />

</RelativeLayout>

现在,在设置pull to refresh布局时设置布局:

ActionBarPullToRefresh.from(getActivity()).listener(new OnRefreshListener() {

    @Override
    public void onRefreshStarted(View view) {
        refresh();
    }

}).headerLayout(R.layout.header).build()).setup(ptrLayout);

我们今天的关于Chris Banes实现ActionBar-PulltoRefresh,库错误等的分享就到这里,谢谢您的阅读,如果想了解更多关于actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok、ADChromePullToRefresh iOS 下拉刷新、android ActionBar-PullToRefresh 下拉刷新的使用方法、android – ActionBar – PullToRefresh的相关信息,可以在本站进行搜索。

本文标签: