列表视图页脚正在留空并且不会被删除

时间:2015-05-26 09:59:54

标签: java android xml android-layout android-fragments

我正在使用列表视图页脚,它只是一个按钮。每当我使用加载更多按钮更新列表时,它会在底部添加额外的空间。此外,我试图在加载所有d数据时删除页脚。

  

在oncreate中初始化按钮

btnLoadMore = new Button(getActivity());
        btnLoadMore.setText("Load More");
        btnLoadMore.setWidth(700);
        btnLoadMore.setHeight(30); 
  

然后在后执行

                    mainAdapter = new SimpleAdapter(  
                            getActivity(), mainfooditems,
                            R.layout.list_mealiteml, new String[] {KEY_FLFOODNAME,KEY_FLCALORIES,KEY_FLFOODID,KEY_FLFAT,KEY_FLCARBS,KEY_FLPROTEIN,KEY_FLBRAND,KEY_FLSERVING}, new int[] { 
                                R.id.nameone,R.id.uiduid,R.id.mtvfoodid,R.id.fatoutputval,R.id.carbsoutval,R.id.proteinsoutval,R.id.tvbrandnameone,R.id.tvservingone });
                    // updating listview
                    listMain.addFooterView(btnLoadMore);
                    listMain.setAdapter(mainAdapter);
                    mainAdapter.notifyDataSetChanged();
state3();
  

state3如下:

public void state3(){
        search.clearFocus();

        setListViewHeightBasedOnChildren(listMain);
        setListViewHeightBasedOnChildren(listCustom);
        setListViewHeightBasedOnChildren(listRecent);
        tvError.setVisibility(View.INVISIBLE);
        tvMessage.setVisibility(View.INVISIBLE);
        finalfoodidint=Integer.parseInt(finalfoodid);
        if(finalfoodidint > oldlastid){

            System.out.println("1.5 + " + finalfoodidint);
            System.out.println("1.6 + " + oldlastid);

        }
        else if(finalfoodidint == oldlastid){
            //listMain.removeFooterView(btnLoadMore);
            listMain.removeFooterView(btnLoadMore);
            System.out.println("1.7 + " + finalfoodidint);
            System.out.println("1.8 + " + oldlastid);
        }
        else{
            listMain.removeFooterView(btnLoadMore);
            System.out.println("1.9 + " +finalfoodidint);
            System.out.println("1.10 + " +  oldlastid);
        }
    }

It appears

3 个答案:

答案 0 :(得分:0)

删除标题时,请尝试在列表中调用notifyDataSetChanged()。 尝试在public void state3()

的末尾添加此行
listMain.getAdapter().notifyDataSetChanged();

答案 1 :(得分:0)

  

我将public void state3中的代码更改为

public void state3(){
        search.clearFocus();
        listMain.removeFooterView(btnLoadMore); 
        tvError.setVisibility(View.INVISIBLE);
        tvMessage.setVisibility(View.INVISIBLE);
        finalfoodidint=Integer.parseInt(finalfoodid);
        if(finalfoodidint > oldlastid){

            listMain.addFooterView(btnLoadMore);

            System.out.println("1.5 + " + finalfoodidint);
            System.out.println("1.6 + " + oldlastid);

        }
        else if(finalfoodidint == oldlastid){
            //listMain.removeFooterView(btnLoadMore);
            listMain.removeFooterView(btnLoadMore);
            System.out.println("1.7 + " + finalfoodidint);
            System.out.println("1.8 + " + oldlastid);
        }
        else{
            listMain.removeFooterView(btnLoadMore);
            System.out.println("1.9 + " +finalfoodidint);
            System.out.println("1.10 + " +  oldlastid);

        }
        listMain.setAdapter(mainAdapter);
        mainAdapter.notifyDataSetChanged();
        setListViewHeightBasedOnChildren(listMain);
        setListViewHeightBasedOnChildren(listCustom);
        setListViewHeightBasedOnChildren(listRecent);
    }
  

还将后执行更改为

mainAdapter = new SimpleAdapter(  
                                getActivity(), mainfooditems,
                                R.layout.list_mealiteml, new String[] {KEY_FLFOODNAME,KEY_FLCALORIES,KEY_FLFOODID,KEY_FLFAT,KEY_FLCARBS,KEY_FLPROTEIN,KEY_FLBRAND,KEY_FLSERVING}, new int[] { 
                                    R.id.nameone,R.id.uiduid,R.id.mtvfoodid,R.id.fatoutputval,R.id.carbsoutval,R.id.proteinsoutval,R.id.tvbrandnameone,R.id.tvservingone });
                        // updating listview

                        state3();

答案 2 :(得分:0)

更改你的" setListViewHeightBasedOnChildren"方法如下。

 <script>
$(function(){
    var $div = $('<div class="foo"></div>').
       /*attach or listen to events here*/
       .appendTo('body');
});
</script>