Where to get Outside Data from RemoteViewsService.RemoteViewsFactory - android

I need to populate a ListView in a Homescreen Widget. I know I use RemoteViewsService.RemoteViewsFactory as a sort of Adapter.
I also know how to populate the rows in getViewAt() method to show this.
However, I need to populate an ArrayList of Objects from the Network and pass that into the getViewAt() I am not sure where or how to go about doing this?
In a normal adapter, I simply pass this in the constructor. Would it be the same here?

Related

Getting a variable from fragment to recyclerview Adapter and listening its value in adapter

There is a need of sorting record in recycler view adapter, based on the platform chosen from buttons in fragment.
I can't use interface as I already used in Adapter to listen in fragment. if I use interface now it will cause cyclic redundancy.
Can you please let me know the procedure for this. Thanks!
I'm sorry I'm only allowed to upload image links, Thank you very much for all your support and looking forward for the solution!!
you get a variable from the fragment using intent, later you pass that variable to the recycler view through the adapter (create a method to update a variable inside the adapter class) and I'll say to update the adapter everytime your fragment variable changes.
if you provide a screenshot of your code I can give a better answer, it depends how you implemented it.

Updating a ListView With CursorAdapter When Querying Database

I have a ListView and an CustomListAdapter that extends CursorAdapter. I'm using a LoaderManager to load the data into my CustomListAdapter when I first load the Fragment containing the ListView. That all works fine. I'm using ContentProviders so any updates or changes to the underlying data in the database are reflected in the Listview.
Now I want to allow the user to search for specific items in the list. So in other words i want to update the list view based on the search query obtains from the SearchDialog. I've got the SearchDialog working and I'm up to the point where I receive the intent in ParentActivity of the ListViewFragment, with the search query. However I'm not really sure what I should be doing now.
I was thinking of detaching and then re-attaching the Fragment to the ParentActivity passing the search query string to the ListViewFragment so that the onCreateLoader() method of the fragment could use the query to do another search. This seemed like an easy way to achieve what I wanted to do.
Is this the correct way to update a ListView based on a search? Or is this overkill for what I'm trying to do? Does anyone have any other suggestions?
Kind Regards
For anyone that wants to know, my requirement changed and instead of using the same Activity to view the results, I sent the results to a new SearchResultActivity that was re-using the ListViewFragment.
I created an instance variable on the ListViewFragement that would store the query string. When creating a new instance of the Fragment, it expects a value for this query string. When I load the Fragment from my first Activity, the string is null and the onCreateLoader() by default loads all the results. When I load the Fragment from SearchResultActivity I pass in the query result from the SearchDialog and the onCreateLoader() will use the query to return a Cursor based on a specific selection.
I didn't need to attach and re-attach the fragment in anyway. However if I was to use the same Activity and ListViewFragment to display the search results, instead of detaching and re-attaching the fragment to the activity, I would probably use the restartLoader method of LoaderManager:
LoaderManager Doc

Proper way to listen to data changes, and update UI accordingly

I'm storing numerical data (streamed from a Bluetooth connection running as a background Service) on a static ArrayList.
Every time my List is modified, I need to update my UI accordingly (which is a plot on an Activity).
I've read about:
Implementing the Observer pattern interface
Using Loaders
Which solution is the most appropriate? Is there any other better/simpler solution?
I would set an android.widget.Adapter (perhaps a BaseAdapter or ListAdapter depending on your data) for the view to provide the data to the view. When the data is updated, simply call the adapter's notifyDataSetChanged() method to update the view.

How should i add the values present in onActivityResult to the child views of ExpandableListView?

I have expandableListView consists of GroupViews & childViews. MyActivity is extending Activity. Now I want to add all the data present in for loop of onActivityResult to childViews of ExpandableListView. How should I do this..?
Please help me...
Anyone can plz help me....
I imagine you have your Adapter class for your ExpandableListVieW. Your Adapter class is inicialized by some form of data you are storing. Update that storage with the new data. I read in a lot of posts to call the notifyDataSetChanged() method on your adapter, it depends on what kind of Adapter you are using. Mine Adapter extends from BaseAdapter, that class does not have that function, but it updates my list automaticly after i added the new data to my storage.

Android: refreshing list view from different activity

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

Categories

Resources