仿sina微博的listview更多分页按钮

 更新时间:2016年9月20日 20:01  点击:1630
本文章分享一个简单的android开发实现,功能是仿sina微博的listview更多分页按钮,有需要的朋友可以安看看。

因为百事查需要,需要制作这样的更多分页按钮,因为感觉新浪微博的更多分页按钮比较好,就尝试做了一下。
1、首先需要考虑布局,就是footer的布局,如下:

 代码如下 复制代码

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

<LinearLayout android:layout_width="fill_parent" android:orientation="vertical"

android:layout_height="wrap_content" android:focusable="true"

xmlns:android="http://schemas.android.com/apk/res/android"

android:background="@drawable/loadmore" android:layout_centerVertical="true"

android:layout_centerHorizontal="true">

<!--

<Button android:id="@+id/loadMoreButton"

android:layout_width="fill_parent"

android:layout_height="wrap_content" android:text="更多" />

-->

<LinearLayout android:gravity="center" android:layout_height="wrap_content"

android:orientation="vertical" android:layout_width="fill_parent">

<ImageView android:background="@drawable/divider"

android:layout_height="2.0dip" android:layout_width="fill_parent" />

</LinearLayout>

<LinearLayout android:gravity="center" android:layout_gravity="center"

android:orientation="horizontal" android:layout_centerVertical="true"

android:layout_width="fill_parent" android:layout_height="60dip">

<TextView android:textSize="20.0sp" android:textColor="#ff545454"

android:gravity="center" android:id="@id/tv_msg" android:text="更多"

android:layout_width="fill_parent" android:layout_height="wrap_content"/>

<LinearLayout android:gravity="center" android:layout_height="wrap_content"

android:layout_gravity="center" android:orientation="horizontal"

android:id="@+id/llloading" android:layout_width="fill_parent">

<ProgressBar android:layout_gravity="center_vertical"

android:id="@id/footprogress" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:indeterminateBehavior="repeat"

style="?android:progressBarStyleSmallInverse" />

<TextView android:textColor="#ff000000" android:gravity="left|center"

android:padding="2.0px" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text="读取中" />

</LinearLayout>

</LinearLayout>

</LinearLayout>
期中上面的一个@drawable/loadmore是一个选择器如下

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

<selector

xmlns:android="http://schemas.android.com/apk/res/android"

>

<item

android:state_pressed="false"

android:drawable="@drawable/listview_gradient"

>

</item>

<item

android:state_pressed="true"

android:drawable="@drawable/list_selector_background_pressed"

>

</item>

</selector>其中list_selector_background_pressed系统带的一个按钮在listview源代码中可以找到或sdk中也有

2、同时加载footer布局

list_footer = (LinearLayout)LayoutInflater.from(FansActivity.this).inflate(R.layout.sinalist_footer, null);

tv_msg = (TextView)list_footer.findViewById(R.id.tv_msg);

loading = (LinearLayout)list_footer.findViewById(R.id.llloading);

//btloadmore = (Button)list_footer.findViewById(R.id.loadMoreButton);

listView = getListView();

top_panel = (View)findViewById(R.id.fans_top);

top_btn_left = (Button)top_panel.findViewById(R.id.top_btn_left);

top_btn_right = (Button)top_panel.findViewById(R.id.top_btn_right);

top_title = (TextView)top_panel.findViewById(R.id.top_title);

listView.addFooterView(list_footer, null, false);//利用FooterVIew分页动态加载,参数false是不让选择
3、list_footer中增加按钮事件如下

list_footer.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

try {

// Toast.makeText(FansActivity.this, "我将消失了",

// Toast.LENGTH_SHORT).show();

//list_footer.setBackgroundColor(Color.YELLOW);

//list_footer.invalidate();

new FansThread().start();

//tv_msg.setEnabled(false);

tv_msg.setVisibility(View.GONE);// 隐藏更多提示的TextView

loading.setVisibility(View.VISIBLE);// 显示最下方的进度条

} catch (Exception e) {

e.printStackTrace();

}

}

});

效果如下

本文章分享一篇关于android与Web服务器交互时的cookie使用实例有需要的同学可以参考一下。

下面是具体的代码
/**

* 向网站发送get请求,url需按照api要求写,返回取得的信息。

* //这个专门给大众点评传入cookie参数用,目的是为了获得用户选择的城市信息

* @param url

* @param client

* @return String

* @author lvqiyong

*/

 代码如下 复制代码

public static String getRequest1(String url, DefaultHttpClient client,

String charset) throws Exception {

String result = null;

int statusCode = 0;

HttpGet getMethod = new HttpGet(url);

Log.d(TAG, "do the getRequest,url=" + url + "");

try {

getMethod.setHeader("User-Agent", USER_AGENT);

getMethod.setHeader("Cookie", "cy=" + value);//这个专门给大众点评传入cookie参数用,目的是为了获得用户选择的城市信息

// 添加用户密码验证信息

// client.getCredentialsProvider().setCredentials(

// new AuthScope(null, -1),

// new UsernamePasswordCredentials(mUsername, mPassword));

 

HttpResponse httpResponse = client.execute(getMethod);

// statusCode == 200 正常

statusCode = httpResponse.getStatusLine().getStatusCode();

Log.d(TAG, "statuscode = " + statusCode);

// 处理返回的httpResponse信息

if (statusCode == 200) {

result = retrieveInputStream(httpResponse.getEntity(), charset);

Cookie cookie;

String cookname,cookvalue;

List<Cookie> cookies = client.getCookieStore().getCookies();

if (cookies.isEmpty()) {

Log.i(TAG, "-------Cookie NONE---------");

} else {

for (int i = 0; i < cookies.size(); i++) {

// 保存cookie

cookie = cookies.get(i);

cookname = cookie.getName().trim();

cookvalue = cookie.getValue().trim();

if(cookname.equals("cy")){

name = cookname;

value = cookvalue;

}

}

}

} else

result = "networkerror";

} catch (ConnectTimeoutException e) {// 超时或网络连接出错

result = "timeouterror";

// e.printStackTrace();

} catch (ClientProtocolException e) {

result = "networkerror";

// e.printStackTrace();

} catch (Exception e) {

result = "readerror";

Log.e(TAG, e.getMessage());

throw new Exception(e);

} finally {

getMethod.abort();

}

return result;

}

[!--infotagslink--]

相关文章

  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • 利用JS实现点击按钮后图片自动切换的简单方法

    下面小编就为大家带来一篇利用JS实现点击按钮后图片自动切换的简单方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2016-10-25
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
  • Springboot如何使用mybatis实现拦截SQL分页

    这篇文章主要介绍了Springboot使用mybatis实现拦截SQL分页,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-19
  • PHP 一个完整的分页类(附源码)

    在php中要实现分页比起asp中要简单很多了,我们核心就是直接获取当前页面然后判断每页多少再到数据库中利用limit就可以实现分页查询了,下面我来详细介绍分页类实现程序...2016-11-25
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • AngularJS实现分页显示数据库信息

    这篇文章主要为大家详细介绍了AngularJS实现分页显示数据库信息效果的相关资料,感兴趣的小伙伴们可以参考一下...2016-07-06
  • C#实现带进度条的ListView

    这篇文章主要介绍了C#实现带进度条的ListView 的相关资料,需要的朋友可以参考下...2020-06-25
  • BootStrap栅格系统、表单样式与按钮样式源码解析

    这篇文章主要为大家详细解析了BootStrap栅格系统、表单样式与按钮样式源码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-01-23
  • 基于jquery实现表格无刷新分页

    这篇文章主要介绍了基于jquery实现表格无刷新分页,功能实现了前端排序功能,增加了前端搜索功能,感兴趣的小伙伴们可以参考一下...2016-01-08
  • C#获取鼠标在listview右键点击单元格的内容方法

    下面小编就为大家带来一篇C#获取鼠标在listview右键点击单元格的内容方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • vue实现页面打印自动分页的两种方法

    这篇文章主要为大家详细介绍了vue实现页面打印自动分页的两种方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-29
  • C#使用浏览按钮获得文件路径和文件夹路径的方法

    这篇文章主要介绍了C#使用浏览按钮获得文件路径和文件夹路径的方法,结合实例形式分析了C#浏览器事件响应及文件操作相关技巧,需要的朋友可以参考下...2020-06-25
  • 基于JavaScript实现手机短信按钮倒计时(超简单)

    在淘宝等购物网站,我们都会看到一个发送短信倒计时的按钮,究竟是如何实现的呢?下面小编通过本篇文章给大家分享一段代码关于js实现手机短信按钮倒计时,需要的朋友参考下...2016-01-02
  • python编程PyQt5创建按钮及触发点击事件示例解析

    这篇文章主要为大家介绍了python编程使用PyQt5如何创建按钮及触发点击事件的示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步...2021-10-29
  • C#实现读取DataSet数据并显示在ListView控件中的方法

    这篇文章主要介绍了C#实现读取DataSet数据并显示在ListView控件中的方法,涉及C#操作DataSet及ListView控件的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • C# DataTable分页处理实例代码

    有时候我们从数据库获取的数据量太大,而我们不需要一次性显示那么多的时候,我们就要对数据进行分页处理了,让每页显示不同的数据。...2020-06-25
  • jquery mobile实现可折叠的导航按钮

    这篇文章主要为大家详细介绍了jquery mobile实现可折叠的导航按钮,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-03-13