2011-12-30 16 views
0

私はページングでリストビューを使用していますので、リストビューを最後に追加する必要があります。 私はコードを持っています - 何がWebでIfoundから統合されています。しかし、addFooterメソッドが呼び出されていることがわかります(2つの場所で言及していますが、フッターは画面に表示されません)。Androidのリストビューページング - フッタをエージングしますが、リスト内にフッタがありません

関連コード:

public class GlobalBookTab extends ListActivity implements OnClickListener 

{民間最終列MTAG = "GlobalBook"。あなたがリストについては、前setAdapterにaddFooterメソッドを呼び出す必要が

private EditText     mSearchEditText   = null; 
private String      mLastSearchString  = null; 

private View      mCategoriesView   = null; 

private int       mQueryPageNumber  = 1; 
private ServerWrapper.SortByEnum mLastSearchSorting  = SortByEnum.NO_SORTING; 
private GlobalRecipeListAdapter  mListViewAdapter  = null; 

private boolean      mIsCategorySearch  = false; 
private Recipe.CategoryEnum   mSearchCategory   = Recipe.CategoryEnum.NO_CATEGORY; 

private ImageView     mSortByRateView   = null; 
private ImageView     mSortByDifficultyView = null; 
private ImageView     mSortByTimeView   = null; 

private View      mFooterView    = null; 
private boolean      mLoadingMore   = false; 
private ListView     mListView    = null; 

private LayoutInflater    mInflater    = null; 

/* 
* (non-Javadoc) 
* @see android.app.Activity#onCreate(android.os.Bundle) 
*/ 
@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.global_book); 

    mInflater   = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)); 

    mListView   = this.getListView(); 
    mListViewAdapter = new GlobalRecipeListAdapter( this, 
                 R.layout.recipes_list_view_entry, 
                 new ArrayList<Recipe>()); 

    mFooterView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false); 

    setListAdapter(mListViewAdapter); 
} 

/* 
* (non-Javadoc) 
* @see android.view.View.OnClickListener#onClick(android.view.View) 
*/ 
public void onClick(View v) 
{ 
    switch(v.getId()) 
    { 
     case R.id.searchImageViewId: 
      mQueryPageNumber = 1; 
      mLastSearchSorting = SortByEnum.NO_SORTING; 
      mLastSearchString = mSearchEditText.getText().toString(); 
      if(mIsCategorySearch == false) 
      { 
       mSearchCategory = CategoryEnum.NO_CATEGORY; 
      } 

      SearchButtonClicked(); 

     default: 
      Log.e(mTAG, "Unknown clickId"); 
      return; 
    } 
} 


/** 
* Used when the search button is clicked 
*/ 
private void SearchButtonClicked() 
{ 
    Log.d(mTAG, "Searching for recipe - " + mSearchEditText.getText().toString()); 

    performSearchBackgroundTask task = new performSearchBackgroundTask(); 
    task.execute(); 
    mFooterView = mInflater.inflate(R.layout.listfooter, null, false); 
    getListView().addFooterView(mFooterView); 
} 

private class performSearchBackgroundTask extends AsyncTask <Void, Void, Void> 
{ 
    ArrayList<Recipe>    mRecipes  = null; 
    private ProgressDialog   Dialog   = new ProgressDialog(GlobalBookTab.this); 
    private boolean     mExecutedOK  = false; 
    private ServerException.Id  mExceptionId = ServerException.Id.Id_MAX; 

    protected void onPreExecute() 
    { 
     Dialog.setMessage("Please wait..."); 
     Dialog.show(); 
    } 

    protected void onPostExecute(Void unused)  
    { 
     if(Dialog.isShowing()) 
     { 
      Dialog.dismiss(); 
     } 

     if(mExecutedOK == true) 
     { 
      if(mRecipes.size() == 0) 
      { 
       Toast.makeText(getApplicationContext(), 
           "No matching results", 
           Toast.LENGTH_LONG).show(); 
      } 
      else 
      { 
       ChangeCategoriesVisibility(View.GONE); 
       ChangeSortingVisibility(View.VISIBLE); 

       if(mQueryPageNumber != 1) 
       { 
        mListViewAdapter.clear(); 
       } 

       if(mRecipes != null) 
       { 
        for(int i = 0; i < mRecipes.size(); ++i) 
        { 
         if(mRecipes.get(i) != null) 
         { 
          mListViewAdapter.add(mRecipes.get(i)); 
         } 
        } 
       } 

       mListViewAdapter.notifyDataSetChanged(); 

       // Might be more results 
       if(mRecipes.size() == 5) 
       { 
        mFooterView = mInflater.inflate(R.layout.listfooter, null, false); 
        mListView.addFooterView(mFooterView); 
       } 
       else 
       { 
        mListView.removeFooterView(mFooterView); 
       } 
      } 
     } 
     else 
     { 
      switch(mExceptionId) 
      { 
       case FAILED: 
        Toast.makeText(getApplicationContext(), 
            "No matching results", 
            Toast.LENGTH_LONG).show(); 
        break; 

       case UNABLE_TO_CONNECT_TO_SERVER: 
        Toast.makeText(getApplicationContext(), 
            "Failed to connect to server", 
            Toast.LENGTH_LONG).show(); 
        break; 
      } 
     } 
    } 

    @Override 
    protected Void doInBackground(Void... params) 
    { 
     // Do your background data fetching here 
     ServerWrapper    webService = new ServerWrapper(); 
     try 
     { 
      mRecipes = webService.SearchRecipe(mLastSearchString, 
               mQueryPageNumber, 
               mLastSearchSorting, 
               mSearchCategory); 
     } 
     catch(ServerException e) 
     { 
      mExecutedOK  = false; 
      mExceptionId = e.eId(); 

      return null; 
     } 

     mExecutedOK = true; 
     return null; 
    } 
} 

}

答えて

3

。 これ以外のヘッダーやフッターは表示されません。

これがあなたの問題を解決することを願っています。

+0

オハイオ州参照してください。しかし、私はアダプタを設定した後、私が好きなように削除して追加することはできますか?もう一度アダプターを設定する必要がありますか?またはvisibility.GONEを使用しますか? – Yoav

+0

アダプターを再度設定する必要はありません(リストのデータ文字列が完全に変更された場合にのみ設定します)。 フッタービューの表示/非表示をオンにするだけです。 うまくいくはずです。 – akkilis

関連する問題