Я использую listview с пейджингом - так что я должен добавить listview в конце его. У меня есть код, интегрированный с тем, что в Интернете. Но я вижу, что метод addFooter вызывается (в двух местах он упоминается), но нижний колонтитул не отображается на экране?Android listview paging - aggind нижний колонтитул, но нижний колонтитул не отображается в списке
Соответствующий код:
public class GlobalBookTab extends ListActivity implements OnClickListener
{ частной окончательная Строка 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;
}
}
}
Охххх, я вижу. Но после того, как я установил адаптер, я могу удалить и добавить его, как мне нравится? или вам нужно снова установить адаптер? или использовать visibility.GONE? – Yoav
Не нужно снова устанавливать адаптер (устанавливается, только если данные str списка полностью изменены). Просто используйте видимость для просмотра нижнего колонтитула. , который должен работать нормально. – akkilis