使用removeFooterView()删除ListView页脚时出现问题
我正在尝试删除使用与设置它相同的参考设置的页脚。然而,什么也没有发生。
protected void onPostExecute(ArrayList<Recipe> result) {
int CHEF_ID = ChefsRecipeList.this.getIntent().getIntExtra("CHEF_ID", 0);
ListView recipeListView = (ListView)findViewById(android.R.id.list);
View footer = getLayoutInflater().inflate(R.layout.chef_recipe_list_footer, null);
if(!addToExisting){
RecipeManager.getInstance().setRecipeList(result);
View header = getLayoutInflater().inflate(R.layout.chef_recipe_list_header, null);
ImageView loadButton = (ImageView)footer.findViewById(R.id.loadmore);
loadButton.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
int CHEF_ID = ChefsRecipeList.this.getIntent().getIntExtra("CHEF_ID", 0);
try {
Log.d("NXTLAOD", "http://api.foodnetworkasia.com/api/mobile/get_recipes?chefId="+ChefManager.getInstance().getChef(CHEF_ID).getId()+
"&format=xml&startIndex="+(RecipeManager.getInstance().getRecipeList().size()+1)+"&endIndex="+(RecipeManager.getInstance().getRecipeList().size()+24));
new XMLRecipesParser(true).execute(new URL[] { new URL("http://api.foodnetworkasia.com/api/mobile/get_recipes?chefId="+ChefManager.getInstance().getChef(CHEF_ID).getId()+
"&format=xml&startIndex="+RecipeManager.getInstance().getRecipeList().size()+"&endIndex="+(RecipeManager.getInstance().getRecipeList().size()+24)) } );
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
ImageView chefPhoto = (ImageView)header.findViewById(R.id.chef_photo);
chefPhoto.setImageBitmap(ImageURLLoader.LoadImageFromURL(ChefManager.getInstance().getChef(CHEF_ID).getLargeURL()));
TextView chefBio = (TextView)header.findViewById(R.id.chef_bio);
chefBio.setText(ChefManager.getInstance().getChef(CHEF_ID).getDescription());
recipeListView.addHeaderView(header);
recipeListView.addFooterView(footer);
recipeListView.setAdapter(new RecipeAdapter(ChefsRecipeList.this));
}else{
RecipeManager.getInstance().mergeLists(result);
RecipeAdapter wrapperAdapter=(RecipeAdapter) ((HeaderViewListAdapter)recipeListView.getAdapter()).getWrappedAdapter();
wrapperAdapter.notifyDataSetChanged();
}
if(totalRecipes == RecipeManager.getInstance().getRecipeList().size()){
recipeListView.removeFooterView(footer);
Log.d("FOODREM", "Footer Removed");
}
Log.d("ITCOUNT", totalRecipes+"-"+RecipeManager.getInstance().getRecipeList().size());
updateItemscount();
}
}
I am trying to remove footer I've set using the same reference I used to set it up. However, nothing happens.
protected void onPostExecute(ArrayList<Recipe> result) {
int CHEF_ID = ChefsRecipeList.this.getIntent().getIntExtra("CHEF_ID", 0);
ListView recipeListView = (ListView)findViewById(android.R.id.list);
View footer = getLayoutInflater().inflate(R.layout.chef_recipe_list_footer, null);
if(!addToExisting){
RecipeManager.getInstance().setRecipeList(result);
View header = getLayoutInflater().inflate(R.layout.chef_recipe_list_header, null);
ImageView loadButton = (ImageView)footer.findViewById(R.id.loadmore);
loadButton.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
int CHEF_ID = ChefsRecipeList.this.getIntent().getIntExtra("CHEF_ID", 0);
try {
Log.d("NXTLAOD", "http://api.foodnetworkasia.com/api/mobile/get_recipes?chefId="+ChefManager.getInstance().getChef(CHEF_ID).getId()+
"&format=xml&startIndex="+(RecipeManager.getInstance().getRecipeList().size()+1)+"&endIndex="+(RecipeManager.getInstance().getRecipeList().size()+24));
new XMLRecipesParser(true).execute(new URL[] { new URL("http://api.foodnetworkasia.com/api/mobile/get_recipes?chefId="+ChefManager.getInstance().getChef(CHEF_ID).getId()+
"&format=xml&startIndex="+RecipeManager.getInstance().getRecipeList().size()+"&endIndex="+(RecipeManager.getInstance().getRecipeList().size()+24)) } );
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
ImageView chefPhoto = (ImageView)header.findViewById(R.id.chef_photo);
chefPhoto.setImageBitmap(ImageURLLoader.LoadImageFromURL(ChefManager.getInstance().getChef(CHEF_ID).getLargeURL()));
TextView chefBio = (TextView)header.findViewById(R.id.chef_bio);
chefBio.setText(ChefManager.getInstance().getChef(CHEF_ID).getDescription());
recipeListView.addHeaderView(header);
recipeListView.addFooterView(footer);
recipeListView.setAdapter(new RecipeAdapter(ChefsRecipeList.this));
}else{
RecipeManager.getInstance().mergeLists(result);
RecipeAdapter wrapperAdapter=(RecipeAdapter) ((HeaderViewListAdapter)recipeListView.getAdapter()).getWrappedAdapter();
wrapperAdapter.notifyDataSetChanged();
}
if(totalRecipes == RecipeManager.getInstance().getRecipeList().size()){
recipeListView.removeFooterView(footer);
Log.d("FOODREM", "Footer Removed");
}
Log.d("ITCOUNT", totalRecipes+"-"+RecipeManager.getInstance().getRecipeList().size());
updateItemscount();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要调用
listView1.setAdapter(adapter)
来刷新列表视图。如果这不起作用,另一个解决方案是将页脚视图的高度设置为 0px。如果您打算稍后再次使用页脚视图,这是一个更好的解决方案。You might have to call
listView1.setAdapter(adapter)
to refresh the listview. If that doesn't work, another solution is to make the height of the footer view to 0px. This is a better solution if you are planning to use the footer view later on again.您还可以将页脚可见性设置为“GONE”。为此,您需要使用线性布局包裹页脚的内容,然后将线性布局可见性设置为 GONE。
在下面的示例中,我将 LogoLinearLayout 的可见性设置为 GONE。
You can also set the footer visibility for GONE. To do that, you need to wrap the content of your footer using a linearlayout, then you set the linearlayout visibility to GONE.
In the example bellow I set the visibility of LogoLinearLayout to GONE.
我在许多与隐藏页脚问题相关的帖子中看到过这种类型的解决方案(将页脚视图的高度设置为 0,或设置负边距..),它确实有效,但有两个问题:
- 列表将不再遵循transcriptMode =“正常”,从某种意义上说,如果最后一个项目可见并且新项目添加到列表中,则列表将不会滚动到新添加的项目;
- 当显示键盘并且列表大小更改时,列表将不再显示最后一项。
I have seen this type of solution (setting the footer view's height to 0, or setting negative margins..) on many posts related to hiding the footer issue, and it does work, but with 2 issues:
- the list will not respect the transcriptMode="normal" anymore, in the sense that, if the last item is visible and a new item is added to the list, the list will not scroll to the newly added item;
- when keyboard is shown and list size changed, the list again will not show you the last item.