I am implementing a ContactList screen. If there is no Contact at beginning, I will show an empty experience - something like "No Contact Found, Click + button to add now". If there are contacts, just display all the contacts. Above the contact list, I have a search bar. When you enter keyword, it will do the search. And when there is no result found, it will just show empty list.
SO, I have a listView and an empty view if the list has no data. It works fine for Empty Data. However, when no result found, it still shows the empty view.
View emptyView = rootView.findViewById(android.R.id.empty);
mListView.setEmptyView(emptyView);
Is there a way of differentiating these two?
I think it's very simple.
You have to just create another new View for that "NO RESULTS FOUND".
Something like this one:
View noResultsFoundView = rootView.findViewById(android.R.id.no_results_found_view);
mListView.setEmptyView(noResultsFoundView);
How about you make a if statement if there is data in your list view set visibility to hide
Related
I am making an Simple Android App to test the sorting capability and then use it on my main project that I will be making.
I want to know that suppose I display a list of items to the user with the help of custom objects and custom ArrayAdapter in the listview and there I want to place a sorting button that will sort the list during runtime according to the choice of the user (ex: alphabetically, according to ratings,etc.).
How to display the new list to the user after sorting.
Should I again use the setAdapter method or is there any other way?
When you click Sort Button , perfom sorting on the list , and in the next line write
yourAdapter.notifyDatasetChanged();
it will update your list with the updated(sorted) Data.
First of all, sort your source data base on the choice of the user (ex: alphabetically, according to ratings,etc.)
Ex:
List<String> mData; // your source data
// sort your data ascending order
Collections.sort(mData);
// use your adapter to update your ListView
mArrayAdapter.notifyDataSetChanged();
If you call notifyDatasetChanged() in your adapter your list will be redrawn in the right order in the screen. :) So after you order you list, call adapter.notifyDatasetChanged()
My app mostly works. The only problem is that when I want to delete a single item, the confirmation dialogue pops up as required and once the "yes" button is selected the app still does not delete the item.
It is getting the correct burger name. The burger's name was "hshz", quantity is 4 and price is 6. The log message was:
12-29 05:13:04.963 27316-27316/com.example.omar.burgerinventory D/TEST: Burger name is: hshz
Quantity: 4
Price: $6
The entry data is completely deleted once I hit "yes" on the confirmation dialogue. When I click the entry again, the app crashes. So this means that the data is wiped out but the list item still appears on the list for some reason. So I guess the problem here is that I'm able to delete the data but not clear it from the list.
Your problem is because you are making changes to your database correctly, assuming you are using database, but you are not updating your list adapter telling it that it's underlying data has changed..which has reference to the same old data before deleting the item..you need to fetch the new list from database after the code where you are deleting the item..
Please take a look at this accepted answer.. Android ListView not refreshing after notifyDataSetChanged
.
Also it will help if you post the code for your adapter and where you are deleting the item.
After deleting data, remove data from particular position from list by using:-
try{
al_data.remove(particular_position);
}catch(Exception e){}
notifyDataSetChanged();
You can take good example from this tutorial:
http://belencruz.com/2015/04/refresh-data-in-a-custom-android-adapter/
I have a nasty bug when using Tableviews on Appcelerator.
When I enter the app the user is promoted to enter a username and a password then i fetch data from a Server and display it in the Tableview.
There is a filter method to get specific items from the Server. They are send via a Json and i convert them to TableViewRows.
this works like a charm even multiple times. But when i click on a Row it opens a new View (where the user can interact with the data provided for this row)
The problem starts when I'm returning to that previous view where the TableView is.
It doesn't work anymore.
It does not matter how i populate the TableView data
TableView.data=someData doesn't work, TableView.setData(someData) doesn't work and setting a Timeout to set the Data also does not work.
After adding the Data by the described methods above, the Tableview does not Show the Data. But if i Debug it i can see that the new Rows are added to the Tableview but are not Displayed.
Any suggestions?
I have a dynamic list view that is getting data from server after each 3 seconds and adding new data when ever get new data to the list. Actually i want to set data to list according to list row item text value.Suppose if any row has the text value chat request then it should appear on the top of the list always.
How can i do this?can anyone help me?
Is there any method in android by using that i can filter the text according to that i will able to add that row to the top of the list view.
Actually i am getting data from server and adding to the listview.each after 3 seconds i am getting new data and this data i am adding to list.if this response contain the text chat request then i want after parsing the response the chat request text should be added in the list firstly.
How to filter listview data and add specific text on the top of the row in android listview.Can anyone help me?
I have a custom adapter and whenever i got response i am spiting it and storing data for the list in multiple arraylist because my list row has data like ipaddress,statustext,durationtext and no. of visit text value and one button invite.If any chat request come then invite button will be hide and Accept and deny button will appears and on clicking on accept a chat window open and accept button text change to join and deny button will be invisible.
I have to show chat request message remain at the top of the row until the user does not something.
If you store the date in a List you cann filter the new values and if the value chat you add it to the list with the index eg. list.add("text",0); and than you should rebuild the ListView with the list.
How will i go about saving the state of a listview item during scrolling, so that the recycler does not use it when displaying the next row being. i basically have a listview with 4 textviews and one of the textview is displayed based on a condition, derived from a database. For clarity sake, i will call that dependant textview "A".
my problem is that, simplest case: if "A" is being displayed for only the first item or any other row in the list and its not displayed anywhere else, when scrolling, "A" is displayed on other rows that should not have it. i understand the concept of listview reusing rows, but i can't figure out how to save it on an item, so it doesn't get used in another row. Here is a simplified code with just 2 textview:
holder.viewItemName = (TextView)view.findViewById(R.id.nameId);
holder.viewdescriptionStatus = (TextView)view.findViewById(R.id.viewdescriptionId);
int namecolumn = c.getColumnIndex(DBAdapter.NAME);
String name = c.getString(namecolumn);
holder.viewItemName.setText(name);
int description = c.getColumnIndex(DBAdapter.description);
String descriptionstatus = c.getString(description);
/*problem am having here*/
if(description != null){
holder.viewdescriptionStatus.setText("description available");
holder.viewdescriptionStatus.setTextColor(Color.BLUE);
}
as you can see, am using a viewHolder, but i have come to realise that viewHolder doesn't hold the logic as well. i don't know how to save the state of the holder.viewdescriptionStatus based on that condition. Most of the examples i have seen are based on checkboxes. Please anyone with ideas?.. it will be really appreciated.
P.S : i am using bindView() and newView() since i am using an SQLdatabase and SimpleCursorAdapter. i have the same issue with clicking, but i want to solve the scrolling part first. Thank you for your time.
Try this
holder.viewdescriptionStatus.setText(description != null ? "description available" : "");