• 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),也就是默认为可点击状态了

  • 相关阅读:
    datatables排序:ajax数据已经返回,表格不刷新
    php获取名称首字母
    python环境安装
    推荐算法与推荐系统概述
    推荐算法与推荐系统2.LGB模型
    推荐算法与推荐系统3.DeepFM
    推荐算法与推荐系统1 LR模型
    C#进阶——记一次USB HID的各种坑(x86,x64,win10,win7)
    C#进阶——Lambad表达式总结
    The web application [] is still processing a request that has yet to finish。This is very likely........
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_listview_15012418.html
Copyright © 2020-2023  润新知