Tony
Tony

Reputation: 2748

How to display no result in the page if no list is added?

In my upper right corner of my activity, it has a + button used to add new list. For first time user, I want the page display no result if there are no list. If it has list added, it will shows the list and **no result* will dismiss. Can someone tell me how to achieve this ?

I know how to create list/listView, just want to know how to make the **no result* disappeared if new list is added. Do I need to use two xml and two different pages ? Thanks...

Upvotes: 1

Views: 74

Answers (4)

Parth Bhayani
Parth Bhayani

Reputation: 1924

Try this,

listModel is my model in which I have added my data to be fetched, so check that model and simply set the visibility accordingly to that.

if (listModel.size() == 0) {
                txtNoData.setVisibility(View.VISIBLE);
                lstView.setVisibility(View.GONE);           
            }
            else {
                txtNoData.setVisibility(View.GONE);
                lstView.setVisibility(View.VISIBLE);
            }

Upvotes: 0

Iatsenko Anton
Iatsenko Anton

Reputation: 157

you may use Visibility parametr, in your XML must be list and **no result*(no result visibility must be gone) if list not empty - do nothing, if list is empty - do View.Visible on **no result*

Upvotes: 0

Tran Vinh Quang
Tran Vinh Quang

Reputation: 595

In your layout, add TextView has Text "No Result" has visibility is invisible and ListView for render data visible.

In you activity/fragment, check your list item

If list item is null or empty, textView.setVisible(View.VISIBLE)

Else set visible for listView. listView.setVisible(View.VISIBLE)

Upvotes: 1

Navin Gupta
Navin Gupta

Reputation: 803

You can do this by taking a TextView and a ListView inside a RelativeLayout. set textView's visibility to gone. and listView's visibility to visible

and vice-versa

Upvotes: 0

Related Questions