Android listview分页-聚集页脚,但页脚不在列表中显示
我正在使用一个带有分页的listview,所以我应该在它的末尾添加一个listview。 我在网上找到了一个集成的代码。但是我看到addFooter方法被调用(在提到的两个地方),但是页脚没有出现在屏幕上 相关代码:Android listview分页-聚集页脚,但页脚不在列表中显示,android,listview,footer,Android,Listview,Footer,我正在使用一个带有分页的listview,所以我应该在它的末尾添加一个listview。 我在网上找到了一个集成的代码。但是我看到addFooter方法被调用(在提到的两个地方),但是页脚没有出现在屏幕上 相关代码: public class GlobalBookTab extends ListActivity implements OnClickListener { 私有最终字符串mTAG=“GlobalBook” private EditText mSearchEditText=null;
public class GlobalBookTab extends ListActivity implements OnClickListener
{
私有最终字符串mTAG=“GlobalBook”
private EditText mSearchEditText=null;
私有字符串mLastSearchString=null;
私有视图mcategorisview=null;
private int mQueryPageNumber=1;
private ServerWrapper.Sortbynum mLastSearchSorting=Sortbynum.NO\u排序;
私有GlobalRecipeListAdapter mListViewAdapter=null;
私有布尔错误分类搜索=false;
private Recipe.CategoryEnum msearchcontegory=Recipe.CategoryEnum.NO_CATEGORY;
私有ImageView mSortByRateView=null;
private ImageView MSortbyHardicultyView=null;
private ImageView mSortByTimeView=null;
私有视图mFooterView=null;
私有布尔值mLoadingMore=false;
私有ListView mListView=null;
私有LayoutInflater mInflater=null;
/*
*(非Javadoc)
*@see android.app.Activity#onCreate(android.os.Bundle)
*/
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.global_book);
mInflater=((LayoutInflater)this.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE));
mListView=this.getListView();
mListViewAdapter=新的全局RecipeListAdapter(此,
R.layout.recipes\u list\u view\u条目,
新的ArrayList());
mFooterView=((LayoutInflater)this.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)).inflate(R.LAYOUT.listfooter,null,false);
setListAdapter(mListViewAdapter);
}
/*
*(非Javadoc)
*@see android.view.view.OnClickListener#onClick(android.view.view)
*/
公共void onClick(视图v)
{
开关(v.getId())
{
案例R.id.searchImageViewId:
mQueryPageNumber=1;
mLastSearchSorting=SortByEnum.NO_排序;
mLastSearchString=mSearchEditText.getText().toString();
如果(分类错误搜索==false)
{
msearchcontegory=CategoryEnum.NO_CATEGORY;
}
SearchButtonClicked();
违约:
Log.e(mTAG,“未知clickId”);
返回;
}
}
/**
*单击“搜索”按钮时使用
*/
私有void SearchButtonClicked()
{
Log.d(mTAG,“搜索配方-”+mSearchEditText.getText().toString());
performSearchBackgroundTask=新performSearchBackgroundTask();
task.execute();
mFooterView=mInflater.inflate(R.layout.listfooter,null,false);
getListView().addFooterView(mFooterView);
}
私有类performSearchBackgroundTask扩展了AsyncTask
{
ArrayList mRecipes=null;
private ProgressDialog=新建ProgressDialog(GlobalBookTab.this);
私有布尔值mExecutedOK=false;
private ServerException.Id meexceptionid=ServerException.Id.Id_MAX;
受保护的void onPreExecute()
{
setMessage(“请稍候…”);
Dialog.show();
}
受保护的void onPostExecute(未使用的void)
{
if(Dialog.isShowing())
{
Dialog.dismise();
}
if(mExecutedOK==true)
{
如果(mRecipes.size()==0)
{
Toast.makeText(getApplicationContext(),
“没有匹配结果”,
Toast.LENGTH_LONG).show();
}
其他的
{
ChangeCategoriesVisibility(View.GONE);
更改可见性(View.VISIBLE);
if(mQueryPageNumber!=1)
{
mListViewAdapter.clear();
}
如果(mRecipes!=null)
{
对于(int i=0;iprivate 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;
}
}