如何在Android中列表视图为空时隐藏页脚?

时间:2016-04-20 07:40:03

标签: android

我有一个列表视图,其中的项目从服务器加载并在 listview 中有一个页脚,问题是当没有项目时,列表视图是空的页脚是用户可见的。我是什么想如果 listview 中没有项目,则用户看不到页脚。我该怎么做才能帮助我。

我将非常感激。

这是我的代码: -

protected void onPostExecute(final String result) {

        m_ProgressView.setVisibility(View.GONE);
        try {
            m_oResponseobject = new JSONObject(result);// getting response from server
            JSONArray posts = m_oResponseobject.optJSONArray("dealList");


            for (int i = 0; i < posts.length(); i++) {
                JSONObject post = posts.getJSONObject(i);
                item = new CDealAppDatastorage();
                item.setM_szHeaderText(post.getString("dealname"));
                item.setM_szsubHeaderText(post.getString("dealcode"));
                item.setM_n_Image(m_n_FormImage[i]);
                s_oDataset.add(item);

            }

            // LoadMore button
            Button btnLoadMore = new Button(getActivity());
            btnLoadMore.setText("LOAD MORE DEALS");
            btnLoadMore.setBackgroundResource(R.drawable.button_boarder);
            btnLoadMore.setTextAppearance(getActivity(), android.R.style.TextAppearance_DeviceDefault_Small);
            btnLoadMore.setTextColor(Color.WHITE);
            btnLoadMore.setGravity(Gravity.CENTER);



            // Adding Load More button to lisview at bottom
            m_ListView.addFooterView(btnLoadMore);
            m_oAdapter = new CDealAppListingAdapter(getActivity(), s_oDataset);// create adapter object and add arraylist to adapter
            m_ListView.setAdapter(m_oAdapter);//adding adapter to recyclerview
            m_oAdapter.notifyDataSetChanged();
            }

5 个答案:

答案 0 :(得分:1)

像这样隐藏你的页脚:

// Firs check the list size is greater than 0:

if(s_oDataset.size > 0)
{
 // Add your footer here

}else
{
 // Dont not add your footer or Hide your footer
}

答案 1 :(得分:0)

您可以获得列表视图的大小

ZoomControls

然后如果等于零,则更改按钮可见性

listview.getCount();

答案 2 :(得分:0)

请参阅下面的代码,当ListView为空时,您可以隐藏ListView页脚

 if(!s_oDataset.isEmpty()){
        m_ListView.addFooterView(btnLoadMore);
        m_oAdapter = new CDealAppListingAdapter(getActivity(), s_oDataset);// create adapter object and add arraylist to adapter
        m_ListView.setAdapter(m_oAdapter);//adding adapter to recyclerview
        m_oAdapter.notifyDataSetChanged();
  }

答案 3 :(得分:0)

这是代码,希望它能运作

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/Rabbit/PycharmProjects/Final_Project/Final_Project.py", line 59, in search
    return redirect(url_for(details))
  File "/Library/Python/2.7/site-packages/flask/helpers.py", line 268, in url_for
    if endpoint[:1] == '.':

TypeError: 'function' object has no attribute '__getitem__'

答案 4 :(得分:0)

import numpy as np

INTERFACE = input('Enter your interface: ')
def read_path(inputfile="/INTERFACE/PATH_ACC.dat"):
        with open(inputfile, "r") as fileh:
                for lines in fileh:
                        linesplit = lines.split()
                        yield linesplit[0:3]
acc = [idx for idx in read_path()]