my problem is the next one:
I want to use a ListActivity with recursion, so that it is called "x" times, and everytime i click in one article on the list, it is re-calling again the same Activity but it is loading different data, cause what I wanna do is to make menu and sub-menus, and the expandableList is not enough for me because there are gonna be n-levels(i will know dinamically.....).
Anyone has an idea how can I implement it??
Thanks!
Store every data in some kind of N level ArrayList. Write your Adapter class to accept a level of this list. On the item click, it passes to the next level of your ArrayList and you call a notifyDataSetChanged() on your list.
Related
I have an Activity with a Fragment that displays a ListView containing simple TextViews. A menu item can trigger another Activity via an Intent. That new Activity clears the ArrayList underlying the ArrayAdapter for the ListView using ArrayList.clear().
When I backup from the new Activity to my original one with the ListView, and get control in onResume(), I find that my ListView.getChildCount() is the same as when it was left due to the Intent, but the ListView.getCount() is now properly zero!
I have tried using the adapter's clear() method, I have tried Adapter.notifyDataSetChanged() (although I should not have to).
If I modify the underlying ArrayList from within the fragment itself, all seems fine. For example, clicking on an element gives you an option to remove it, move it up or down, etc... That works OK.
Also, If I then leave the List Activity and return to it again, all is well. So clearly the ArrayList is the same list. I never create a new list, only .clear() it.
Any idea how the Child Count can possibly be more than the underlying element count? Perhaps some kind of observer for the ArrayList does not trigger because the Activity is suspended? In which case how could I sync them up again? I have tried invalidate() for example.
This is under API 23.
I seem to have found a workaround. I noticed another post here discussing thread safety. It seemed to have implications if you do not modify your list from the original UI. So, in my onResume(), I just did a setAdapter() again. With the same adapter and list, and viola! All seems well again.
i am facing a problem like , i am developing an android application where all the records coming from database using REST call and displayed using ListView. now on the same screen one button is there to post the new record.
when user click in the button to post the new recored it will come as popup(DialogFragment). if user post any record from there, the record should prepend to the ListView without any rest call.
the user should feel that recored add to the db and immediately displayed on the screen.
Thanks in advance and any help is appreciated.
So, I guess you are using a list adapter which extends from BaseAdapter or ArrayAdapter.
After the user added a new record, you should add this into the list of records and than call the method notifyDataSetChanged() of the adapter. This way, the new record will be immediately displayed on the screen and you can later on add it into your database (before the activity be destroyed).
Here you can see a example with notifyDataSetChanged()
How to correctly implement BaseAdapter.notifyDataSetChanged() in Android
I've just a little question (I hope it's just a little question ;-)).
My current app-project has, of course, a bunch of activities. In one of these activities (I call it DataActivity) I can enter some informationen (stored on a webserver). Another activity (called ListViewActivity) should show all available information stored onto the webserver.
The problem is: My first step is to open the ListViewActivity with a few entries (it works proper at first time). Then I go to the DataActivity to input a new listitem. When I now go back to my ListViewActivity the new entry isn't listed. I think I have to refresh the ListViewActivity ... but I don't exactly know how. ;-)
What can I do to refresh this ListView after adding the new row/listitem, so that all available information will be displayed?
I assume you are calling the init of the list in onCreate. Just implement onResume (or onStart should work as well) and add a refresh() method that recalls the data from your server for your list.
You need to call notifyDataSetChanged() or notifyDataSetInvalidated() of your list adapter when you are back to your ListViewActivity.
I have ListActivity with CustomArrayAdapter. My extension of ArrayAdapter allows me to do add/remove operations with the rows. It works fine...inside ListActivity. But then I need to add/edit rows in my list from different Activity and troubles begin. How can I do that? All I need inside my EditActivity is CustomArrayAdapter object. I made it static and tried. It worked, but is it a right thing?
Thanks for the answers, masters!
What comes in my mind:
One way could be to make your objects in the ArrayList serializable you could pass then the actual list to the next activity via intent and use it there for the adapter.
Other way would be: if you know the ID of the element which you want to delete, pass it as intent, delete it from the ArrayList and set adapter.notifyDataSetChanged();
I don't think to have a static ArrayAdapter class is the right way. This means you affect both activities at the same time. Because none of them have an own object.
Hope this helps
I identified a problem in changing one activity using tab. In one tab activity I'm adding data to my SQLite database, and in the other tab activity I am displaying them using listview(array adapter). But when I come back to add data after adding new items to SQLite, the newly added records are not updated in my listview.
How do I fix this?
You seem to be pulling the list data from a DB. Is there a reason why you are using an ArrayAdapter instead of a CursorAdapter?
Anyway, you should call notifyDataSetChanged() on your list adapter when the data has changed so it can refresh the view.
you can add code to update your listview (via notifyDataSetChanged or some such) by overriding the onResume() method in your activity which is called whenever the activity is brought back to the foreground.
See http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle