Reputation: 645
I am using a listview with paging - so I should add a listview at the end of it. I have a code - integrated from what Ifound in the web. But I see that addFooter method is called (in the two places it is mentioned) but the footer does not appear on the screen?
Relevant code:
public class GlobalBookTab extends ListActivity implements OnClickListener
{ private final String mTAG = "GlobalBook";
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;
}
}
}
Upvotes: 0
Views: 628
Reputation: 1934
You need to call addFooter method prior to setAdapter for list. Else header/footer wont be visible.
Hope this solves your problem.
Upvotes: 3