android-ListView 最後一行添加控制項

來源:互聯網
上載者:User

標籤:

今天在做一個功能的時候,要求必須是在一個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)); } }

 雖然你在這裡增加了自己的控制項,但是,如果你想重新整理這個控制項的狀態,這時候你需要跟listview重新整理類似,也就是每次都要

android-ListView 最後一行添加控制項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.