今天在做一个功能的时候,要求必须是在一个listview下,有一段提示行的文字,自己的那个listview的adapter用的是cursoradapter,这样的话,处理布局的灵活性就大打折扣了。最开始的想法是改变item的布局,然后在adapter中处理,保证在listview加载到最后一行的时候,控制item中添加的textview显示,实现提示效果。但是,这时候会面临很多的问题。比如,最后一行点击事件,最后一行的下划线等。

后来,想到了另外一种方法,就是不再adapter中添加,而是直接在listview中添加,这个很好的解决了问题。代码如下

/* Vanzo:zhangshuli on: Sat, 24 Jan 2015 16:21:40 +0000
*/
private View mAddSlideItem;
private TextView mSearchResult;
// End of Vanzo: zhangshuli public void onCreate1(Bundle icicle) {
MmsLog.d(TAG,"onCreate"); 
initPlugin(this, getIntent()); 
sNeedRequery = true; 
  final Uri u = getIntent().getData();
if (u != null && u.getQueryParameter("source_id") != null) {
  gotoComposeMessageActivity(u)
;  return;
}
ContentResolver cr = getContentResolver(); 
mLayoutSearch = (RelativeLayout) findViewById(R.id.conv_second);
mLayoutSearch.setVisibility(View.GONE);
//得到想要添加的控件
mAddSlideItem = ((LayoutInflater) getSystemService(
Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.search_mms_result, null);        
        mSearchResult = (TextView) mAddSlideItem.findViewById(R.id.search_result); 
mSearchListView = (ListView) findViewById(R.id.list2);
mSearchListView.setItemsCanFocus(true);
mSearchListView.setFocusable(true);
mSearchListView.setClickable(true);
//在末尾添加控件
        mSearchListView.addFooterView(mAddSlideItem);
mTvEmpty = (TextView)findViewById(android.R.id.empty); 
setTitle(""); Contact.addListener(mContactListener); 
mQueryHandler2 = new AsyncQueryHandler(cr) {
protected void onQueryComplete(int token, Object cookie, Cursor c) { 
try {
if (searchProgressDialog != null && searchProgressDialog.isShowing()) {
searchProgressDialog.setDismiss(true);
searchProgressDialog.dismiss();
}
} catch (IllegalArgumentException ex) {
MmsLog.d(TAG,"Dialog.dismiss() IllegalArgumentException");
} if (mIsContentChanged) {
sWaitSaveDraft = false;
mIsContentChanged = false;
}
mIsQueryComplete = true;
/// @} if (c == null) {
/// M: Add for OP09: @{                 mSearchListView.setFocusable(true);
mSearchListView.setFocusableInTouchMode(true);
mSearchListView.requestFocus(); // Remember the query if there are actual results
if (cursorCount > 0) {
SearchRecentSuggestions recent = ((MmsApp)getApplication()).getRecentSuggestions();
if (recent != null) {
recent.saveRecentQuery(searchString, getString(R.string.search_history, cursorCount, searchString));
}
}

如果你想让自己添加的item不可点击,这时候你可以通过

mSearchListView.addFooterView(mAddSlideItem, null, false);

方法来添加。其中第三个参数就是控制你的item状态是否可点击。

其实,我们如果看listview的实现的话,会发现在源码里面,addFooterView(item)中也调用了addFooterView(item,,)方法,它传递的参数是addFooterView(item,null,true),也就是默认为可点击状态了

ListView- 最后一行添加控件的更多相关文章

  1. winfrom如何在listview中添加控件

    private Button btn = new Button(); private void Form1_Load(object sender, EventArgs e) { ListViewIte ...

  2. winform导入导出excel,后台动态添加控件

    思路: 导入: 1,初始化一个OpenFileDialog类 (OpenFileDialog fileDialog = new OpenFileDialog();) 2, 获取用户选择文件的后缀名(s ...

  3. android 在布局中动态添加控件

    第一步 final LayoutInflater inflater = LayoutInflater.from(this); 第二步:获取需要被添加控件的布局 final LinearLayout l ...

  4. 怎样在不对控件类型进行硬编码的情况下在 C#vs 中动态添加控件

    文章ID: 815780 最近更新: 2004-1-12 这篇文章中的信息适用于: Microsoft Visual C# .NET 2003 标准版 Microsoft Visual C# .NET ...

  5. JQuery动态添加控件并取值

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. 给jquery-validation插件添加控件的验证回调方法

    jquery-validation.js在前端验证中使用起来非常方便,提供的功能基本上能满足大部分验证需求,例如:1.内置了很多常用的验证方法:2.可以自定义错误显示信息:3.可以自定义错误显示位置: ...

  7. winform 用户控件、 动态创建添加控件、timer控件、控件联动

    用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...

  8. WinForm用户控件、动态创建添加控件、timer控件--2016年12月12日

    好文要顶 关注我 收藏该文 徐淳 关注 - 1 粉丝 - 3       0 0     用户控件: 通过布局将多个控件整合为一个控件,根据自己的需要进行修改,可对用户控件内的所有控件及控件属性进行修 ...

  9. Pyqt 动态的添加控件

    Pyqt 动态的添加控件 # -*- coding: utf-8 -*- from PyQt4.QtCore import * from PyQt4.QtGui import * import sys ...

随机推荐

  1. CMSIS-RTOS 简介

    CMSIS-RTOS API是基于Arm®Cortex®-M处理器的设备的通用RTOS接口.CMSIS-RTOS为需要RTOS功能的软件组件提供标准化API,从而为用户和软件行业带来了巨大的好处. C ...

  2. 05002_Linux的安装

    1.虚拟机VMware workstation的安装 (1)下载链接:VMware workstation下载 密码:52wt: (2)双击VMware-workstation-full-10.0.2 ...

  3. jquery快速清除复选框、单选框的选中

    $(":checked").attr("checked", "");

  4. C/C++里面的struct和typedef

    今天看到这样的代码 typedef struct _Abc { uint64_t unit_id; ...... } Abc; 开始不理解这个的意思,后来看到这个解释: https://stackov ...

  5. 思科E3200 路由器 DD-WRT 设置花生壳和3322.org动态域名(DDNS)

    花生壳设置(已測试) ddns.oray.com:80 username   aaaa password bbbb 主机名   abc.gicp.net URL       /ph/update?ho ...

  6. FTP配置说明

    1.下载rpm包,如vsftpd-3.0.2-21.el7.x86_64.rpm.可在系统盘里面找到或者下载 2.参考如下步骤.或者见链接http://blog.csdn.net/uq_jin/art ...

  7. spring security oauth2 架构---官方

    原文地址:https://projects.spring.io/spring-security-oauth/docs/oauth2.html Introduction This is the user ...

  8. SFDC 微服务实践之路 2016.12.10 杭州(整理)--转

    原文地址:http://mp.weixin.qq.com/s/8cC4Ewt6yPjnxdYxuNZlFQ 微服务是什么? 微服务是一种细粒度(Fine-Grain)的SOA 或许在座的高朋了解过其概 ...

  9. sql 向上取整 向下取整 四舍五入的实例;

    SELECT CEILING(23.5/4)'向上取整' ---6 :SELECT FLOOR(23.5/4)'向下取整' ---5 :SELECT ROUND(23.5/4,1)'四舍五入' --5 ...

  10. Linux常用PDF阅读软件

    1.福昕阅读器是一款PDF文档阅读器,对中文的支持度非常高.福昕阅读器作为全球最流行的PDF阅读器,能够快速打开.浏览.审阅.注释.签署及打印任何PDF文件. 2.evince是一个支持多种格式的文件 ...