今天在做一个功能的时候,要求必须是在一个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),也就是默认为可点击状态了

最新文章

  1. 【干货分享】流程DEMO-采购预算编制
  2. pdfbox加载pdf时遇到wrappedioexception报错处理方式
  3. 404 Not Found !
  4. http协议(一)基础知识
  5. ios开发中如何隐藏各种bar
  6. Android完美禁用Home键
  7. php练习:每5个商品一排
  8. easyui.combotree.search.js
  9. SIP进行时
  10. asp.net网站 提示Ambiguous match found
  11. selenium借助AutoIt识别上传文件Java篇
  12. [置顶] VC++界面编程之--自定义CEdit(编辑框)皮肤
  13. apk文件伪装zip64格式案例
  14. New Start!
  15. java连接ms sql server各类问题解析
  16. 201521123093 java 第三周学习总结
  17. 编码(ACSII unicod UTF-8)、QT输出中文乱码深入分析
  18. 怎么让DIV在另一个DIV里靠底部显示?
  19. 《Pro SQL Server Internals, 2nd edition》
  20. Jenkins入门,介绍、安装

热门文章

  1. JavaScript【1】(数据类型)
  2. Design Pattern Adaptor 适配器设计模式
  3. legend---二、如何降低编程复杂度
  4. 25.怎样在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块
  5. shrio 加密/编码
  6. 将本地的代码上传到网上SVN库
  7. installp 操作
  8. Tensorlfow学习笔记----collection
  9. Spring Cloud学习笔记【二】Eureka 服务提供者/服务消费者(ribbon)
  10. 利用HTTP代理录制Jmeter脚本