ListView- 最后一行添加控件
今天在做一个功能的时候,要求必须是在一个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- 最后一行添加控件的更多相关文章
- winfrom如何在listview中添加控件
private Button btn = new Button(); private void Form1_Load(object sender, EventArgs e) { ListViewIte ...
- winform导入导出excel,后台动态添加控件
思路: 导入: 1,初始化一个OpenFileDialog类 (OpenFileDialog fileDialog = new OpenFileDialog();) 2, 获取用户选择文件的后缀名(s ...
- android 在布局中动态添加控件
第一步 final LayoutInflater inflater = LayoutInflater.from(this); 第二步:获取需要被添加控件的布局 final LinearLayout l ...
- 怎样在不对控件类型进行硬编码的情况下在 C#vs 中动态添加控件
文章ID: 815780 最近更新: 2004-1-12 这篇文章中的信息适用于: Microsoft Visual C# .NET 2003 标准版 Microsoft Visual C# .NET ...
- JQuery动态添加控件并取值
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 给jquery-validation插件添加控件的验证回调方法
jquery-validation.js在前端验证中使用起来非常方便,提供的功能基本上能满足大部分验证需求,例如:1.内置了很多常用的验证方法:2.可以自定义错误显示信息:3.可以自定义错误显示位置: ...
- winform 用户控件、 动态创建添加控件、timer控件、控件联动
用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...
- WinForm用户控件、动态创建添加控件、timer控件--2016年12月12日
好文要顶 关注我 收藏该文 徐淳 关注 - 1 粉丝 - 3 0 0 用户控件: 通过布局将多个控件整合为一个控件,根据自己的需要进行修改,可对用户控件内的所有控件及控件属性进行修 ...
- Pyqt 动态的添加控件
Pyqt 动态的添加控件 # -*- coding: utf-8 -*- from PyQt4.QtCore import * from PyQt4.QtGui import * import sys ...
随机推荐
- 最长回文字串 (The longest palindrome substring)
这两天去学了一下,觉得下面那篇文章写的很好,有例子,比较容易懂,所以转一下. 以下内容来自:hihoCoder: 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互 ...
- 【Henu ACM Round#20 B】Contest
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 根据时间和原分数. 算出对应的分数就可以了. [代码] #include <bits/stdc++.h> using n ...
- 【Codeforces Round #422 (Div. 2) A】I'm bored with life
[题目链接]:http://codeforces.com/contest/822/problem/A [题意] 让你求a!和b!的gcd min(a,b)<=12 [题解] 哪个小就输出那个数的 ...
- C#读写共享目录
C#读写共享目录 该试验分下面步骤: 1.在server设置一个共享目录.在这里我的serverip地址是10.80.88.180,共享目录名字是test,test里面有两个文件:good.txt和b ...
- OpenCASCADE Incremental Mesh
OpenCASCADE Incremental Mesh eryar@163.com Abstract. OpenCASCADE IncrementalMesh is used to build th ...
- Python爬虫爬取一篇韩寒新浪博客
网上看到大神对Python爬虫爬到非常多实用的信息,认为非常厉害.突然对想学Python爬虫,尽管自己没学过Python.但在网上找了一些资料看了一下,看到爬取韩寒新浪博客的视频.共三集,第一节讲爬取 ...
- 生成不重复的随机数对(C/C++)
1 #include <stdio.h> #include <algorithm> #include <stdlib.h> #include <time.h& ...
- Ubuntu16.04添加HP Laserjet Pro M128fn打印机和驱动
一.全部设置->打印机->添加新打印机 添加打印机 二.选择自动搜索到的网络打印机HP Laserjet Pro M128fn,点击添加. 三.添加打印机完成,打印测试页进行测试. 四. ...
- nvm安装node流程及报错解决
第一步:下载NVM下载nvm并解压 nvm-window 下载地址:https://github.com/coreybutler/nvm-windows/releases 下载文件,然后解压得到nvm ...
- 如何修改Web.Config里面的值
0.先添加 <add key="MAXNUM" value="6" /> 1.读取值 string maxNum = ConfigurationMa ...