CustomListView说明:可下拉刷新,上拉加载,横向滑动接口回调,
/**
* 功能类似ListView,天机以下特性:
* 1. 可下拉刷新,上拉加载,实现CustomListView.OnPullListener接口
* 3. Slide切换,实现CustomListView.OnSlideListener接口
* @author zhanghao 20141029
*/
(需要自定义享用的提示文字)
<string name="refreshing">refreshing</string>
<string name="loading">loading</string>
<string name="release_ref">release to refresh</string>
<string name="pull_toref">pull down to refresh</string>
<string name="latest_update_time">latest update time: <xliff:g id="UPDATE_TIME">%1$s</xliff:g></string>
代码太长,请参看附件源代码
CustomListFragment功能说明:
具有ListFragment所有功能,天机下拉刷新和上拉加载功能,还有Slide左右滑动切换回调接口;
用法介绍:
使用时可用自己的Fragment继承CustomListFragment,重写onCreateView函数:
1. 直接返回custom_list_fragment_content.xml布局Layout,
比如
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
View root = inflater.inflate(R.layout.custom_list_fragment_content, null);
return root;
}
2. 需要外加控件自定义布局myfragment.xml:
(包含custom_list_fragment_content.xml)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/last_synctime_message"
android:layout_width="match_parent"
android:layout_height="@dimen/error_message_height"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:gravity="right|center_vertical"
android:text="@string/no_last_synctime"
android:singleLine="true"
android:ellipsize="end"
android:background="@color/synctime_bar_background"
android:visibility="gone"
/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="?android:attr/listDivider" />
<!-- 包含custom_list_fragment_content.xml -->
<include
layout="@layout/custom_list_fragment_content"
android:id="@+id/list_panel"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
<!-- Message list error overlays are dynamically inserted here -->
</LinearLayout>
然后,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.myfragment, null);
return root;
}
有兴趣的同学可以看看源代码:
package com.custom.listfragment.demo;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
/**
* 功能类似ListFragment,天机以下特性:
* 1. 可下拉刷新,实现CustomListView.OnPullListener接口
* 2. 上拉加载(默认关闭)
* 3. Slide切换,实现CustomListView.OnSlideListener接口
* @author zhanghao 20141029
*/
@SuppressLint("NewApi") public class CustomListFragment extends Fragment {
final private Handler mHandler = new Handler();
final private Runnable mRequestFocus = new Runnable() {
public void run() {
mList.focusableViewAvailable(mList);
}
};
final private AdapterView.OnItemClickListener mOnClickListener
= new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
onListItemClick((ListView)parent, v, position, id);
}
};
ListAdapter mAdapter;
CustomListView mList;
View mEmptyView;
TextView mStandardEmptyView;
View mProgressContainer;
View mListContainer;
CharSequence mEmptyText;
boolean mListShown;
public CustomListFragment() {
}
/**
* Provide default implementation to return a simple list view. Subclasses
* can override to replace with their own layout. If doing so, the
* returned view hierarchy <em>must</em> have a ListView whose id
* is {@link android.R.id#list android.R.id.list} and can optionally
* have a sibling view id {@link android.R.id#empty android.R.id.empty}
* that is to be shown when the list is empty.
*
* <p>If you are overriding this method with your own custom content,
* consider including the standard layout {@link android.R.layout#list_content}
* in your layout file, so that you continue to retain all of the standard
* behavior of ListFragment. In particular, this is currently the only
* way to have the built-in indeterminant progress state be shown.
*/
/**
* Attach to list view once the view hierarchy has been created.
*/
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ensureList();
}
/**
* Detach from list view.
*/
public void onDestroyView() {
mHandler.removeCallbacks(mRequestFocus);
mList = null;
mListShown = false;
mEmptyView = mProgressContainer = mListContainer = null;
mStandardEmptyView = null;
super.onDestroyView();
}
/**
* This method will be called when an item in the list is selected.
* Subclasses should override. Subclasses can call
* getListView().getItemAtPosition(position) if they need to access the
* data associated with the selected item.
*
* @param l The ListView where the click happened
* @param v The view that was clicked within the ListView
* @param position The position of the view in the list
* @param id The row id of the item that was clicked
*/
public void onListItemClick(ListView l, View v, int position, long id) {
}
/**
* Provide the cursor for the list view.
*/
public void setListAdapter(ListAdapter adapter) {
boolean hadAdapter = mAdapter != null;
mAdapter = adapter;
if (mList != null) {
mList.setAdapter(adapter);
if (!mListShown && !hadAdapter) {
// The list was hidden, and previously didn't have an
// adapter. It is now time to show it.
setListShown(true, getView().getWindowToken() != null);
}
}
}
/**
* Set the currently selected list item to the specified
* position with the adapter's data
*
* @param position
*/
public void setSelection(int position) {
ensureList();
mList.setSelection(position);
}
/**
* Get the position of the currently selected list item.
*/
public int getSelectedItemPosition() {
ensureList();
return mList.getSelectedItemPosition();
}
/**
* Get the cursor row ID of the currently selected list item.
*/
public long getSelectedItemId() {
ensureList();
return mList.getSelectedItemId();
}
/**
* Get the activity's custom list view widget.
*/
public CustomListView getListView() {
ensureList();
return mList;
}
/**
* The default content for a ListFragment has a TextView that can
* be shown when the list is empty. If you would like to have it
* shown, call this
没有合适的资源?快使用搜索试试~ 我知道了~
android Fragment 实例 ListFragment listiew 下拉刷新 上拉加载 横向滑动事件监听
共89个文件
class:51个
xml:13个
java:11个
4星 · 超过85%的资源 需积分: 34 94 下载量 5 浏览量
2014-10-31
17:58:13
上传
评论 2
收藏 864KB ZIP 举报
温馨提示
学习Fragment开发, 轻松实现 android Fragment 实例 Listfragment listiew 下拉刷新 上拉加载 横向滑动事件监听
资源推荐
资源详情
资源评论
收起资源包目录
CustomListFragmentDemo.zip (89个子文件)
CustomListFragmentDemo
bin
res
R.txt 30KB
classes
android
support
v7
appcompat
R$layout.class 2KB
R$bool.class 763B
R$id.class 2KB
R$drawable.class 5KB
R$dimen.class 1KB
R$attr.class 5KB
R.class 1015B
R$styleable.class 6KB
R$string.class 1KB
R$integer.class 445B
R$color.class 594B
R$anim.class 629B
R$style.class 9KB
com
custom
listfragment
demo
MainActivity.class 1KB
BuildConfig.class 365B
DataGenerator.class 2KB
CustomListView$1.class 1KB
DetailsFragment$2.class 721B
CustomListFragment.class 7KB
R$layout.class 2KB
R$bool.class 763B
R$id.class 3KB
R$drawable.class 5KB
DetailsFragment.class 6KB
DetailsFragment$3.class 749B
R$dimen.class 2KB
CustomListView$LoadMode.class 1KB
TitlesFragment.class 4KB
CustomListView$2.class 978B
DetailsFragment$1.class 726B
R$attr.class 5KB
CustomListView$OnPaddingListener.class 329B
R$menu.class 418B
DetailsFragment$4.class 962B
CustomListFragment$1.class 881B
CustomListView$PaddingTopAsynTask.class 3KB
R.class 1KB
CustomListFragment$2.class 1KB
R$styleable.class 7KB
CustomListView$RefreshState.class 1KB
CustomListView.class 20KB
CustomListView$OnPullListener.class 520B
R$string.class 1KB
CustomListView$OnSlideListener.class 303B
R$integer.class 445B
R$color.class 594B
CustomListView$OnSoftInputStateListener.class 294B
R$anim.class 629B
R$style.class 9KB
CountingFragment.class 2KB
DetailsActivity.class 1KB
AndroidManifest.xml 925B
res
drawable-ldpi
values-v11
styles.xml 321B
menu
main.xml 419B
values-v14
styles.xml 378B
drawable-hdpi
ic_launcher.png 7KB
drawable-xhdpi
arrow_vertical.png 981B
ic_launcher.png 12KB
drawable-xxhdpi
ic_launcher.png 24KB
values
strings.xml 663B
styles.xml 682B
dimens.xml 213B
drawable-mdpi
ic_launcher.png 4KB
layout
pull_listview_header.xml 3KB
hello_world.xml 384B
activity_main.xml 1KB
custom_list_fragment_content.xml 2KB
values-w820dp
dimens.xml 373B
proguard-project.txt 781B
ic_launcher-web.png 50KB
assets
gen
android
support
v7
appcompat
R.java 40KB
com
custom
listfragment
demo
BuildConfig.java 170B
R.java 176KB
.settings
org.eclipse.jdt.core.prefs 173B
src
com
custom
listfragment
demo
CountingFragment.java 1KB
TitlesFragment.java 3KB
CustomListFragment.java 10KB
DetailsActivity.java 961B
CustomListView.java 23KB
MainActivity.java 1KB
DetailsFragment.java 4KB
DataGenerator.java 1KB
.project 825B
.classpath 466B
project.properties 607B
AndroidManifest.xml 925B
readme.txt 14KB
libs
android-support-v4.jar 741KB
共 89 条
- 1
资源评论
- weixin_389805932017-10-02可以 下面要是横向的菜单就好了
- 欣儿梦语2015-04-23程序里一堆错误,完全不能运行!
- qq_270805932015-08-19很好的学习例子,值得学习,感谢楼主分享
- asqw522015-08-27好难看得懂,太乱了
云水-禅心
- 粉丝: 55
- 资源: 65
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 黑苹果OC引导-0.9.1
- Redis 服务等过期策略和内存淘汰策略解析
- debian配置FTP服务
- 基于Matlab和CPLEX的2变量机组组合调度程序(注释完全,可直接运行)(文档加Matlab源码)
- 基于TMS320F2812设计复合频率信号频率计AD09硬件(原理图+PCB )+CCS软件源码+详细设计文档资料.zip
- MultivariateAnalysis(目标规划、多元分析与插值的相关例子)(注释完全,可直接运行)(文档加Matlab源码)
- 黑苹果OC引导-0.9.2
- 数据库实验-王珊.doc
- unity读取excel工具 使用3.5即可
- Matplotlib 是一个 Python 的绘图库 Matplotlib 绘图指南与功能介绍.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功