Parsing RSS XML feed into a listview - java

Getting straight to the point, I'm new to this and trying to use this https://github.com/matshofman/Android-RSS-Reader-Library library to parse an rss feed and put all that into a listview. (I don't mind if you give me an alternate solution to this though. I picked this simply because it looked like it would be easier to understand and less work....)
MY problem is that I'm not sure how to do it, and when I read up on it on google it's either darn confusing or Eclipse says there's something wrong with it and gives me an error.
So :: can someone please explain to me, how I should go about doing this. I understand how to put a URL into this feed, and generally how listviews work,
but I'm getting stumped on passing the data that the library extracts from the feed and passing it into my listview. I don't have a clue how to write out java code that tells it to take data that this library passed and say, put it into this string.
I'm also confused about how a listadapter / adapter works. I think I understand how to write it, but all my past attempts have given me errors and I'm not sure what's the problem there.
It would also be nice if someone could explain how the list_layout thing works out. By that, I mean when you create a new xml file and define how one row of the listview looks, but I don't see how it gets linked up with the main xml file with a single listview.
Thanks for helping me out - it's a school project....
(btw, please be simple with the explanations. I think the main problem i'm having is that a lot of the tutorials like using very technical language, and it ends up not getting the point across to me. Even if you give me a chunk of code, and tell me all that parses my url, that's all i need.)

A ListView needs an Adapter to know what the data is and how much of the data there is. The ListView asks the adapter for a view to display a single item using the adapter's method getView(....). In this method you should inflate your view (the item) using the getLayoutInflater().inflate(..). You then get a view for which you can get the specific sub-views by using the findViewById(...) method on that view. Of each sub-view you set the value of a part of your item.
In order to avoid having to inflate a view for each and every item the ListView recycles item views whenever possible, therefore the method getView(...) receives a view, if that view is not null you can use that view instead of inflating a new view.
While reading your data, or when you have read all your data, you need to tell the adapter that the data has changed, which then tells your ListView that it needs to redisplay data. You tell your adapter by calling notifyDataSetChanged().
There is a Google I/O session on the ListView, maybe that might be interesting to watch: http://www.google.com/intl/nl/events/io/2010/sessions/world-of-listview-android.html

In you android-sdk under /samples/android-xx/ there is a sample called "XmlAdapter" which contains a RSS-feed activity. Could be a helpful alternative.

Related

Recyclerview in a recyclerview activity

using firebase-ui and some coding I have set up my code to work like this:
1) it retrieves data from firebase (image, text and so on), then it passes them to another activity.
2) the new activity receives datas like strings and shows them.
Just to give you an idea I am looking forward to building a streaming app. What I want to do is to show an episode list via recyclerview.
What I am doing right now is a nested scroll view and a copy-paste script to pass up to 26 episodes, but this is not a really good method and I would like to have some suggestions in order to go forward in the best way and solve this problem.
this is a screenshot of the app: https://imgur.com/a/vgBnZTA I am just passing strings to the 2nd activity, then i check if it is not a null string, if it is i hide the layout, otherwise it shows, but it is just a copypaste of code. I hope i was clear enough
Thanks everyone for your support

android gridview change item text

Ive got some gridView and some function which is called when a message arrives from server. In this function I get the values from server and I want to write this value in specific item in the gridView.
The problem is I dont have any idea how can I rewrite text of som Item in the gridView and I couldn find any answer on the internet :/
First you need to to add the received data into arraylist which you used to populate your grid view . You can add the received data into any position of arraylist as you need.
Then update the Arrayadapter using the following command
adapter.notifyDataSetChanged();
I understand up to some point. In my expatiation i think your set by using adapter right. So the simple solution is once you get the new items for a grid. call the setadapter again. Then that will set the new items. Try it once.
Actually i have to comment out but i don't have that much points.

dynamic layout based on dynamic data in android

i need to get some json data from a server and then create elements to show that data. due the data is into an array of objects, i need to put this code into a loop.
example:
name - address
save button
name - address
save button
name - address
save button
i am thinking to create an array of linearlayouts with the needed widgets inside and repeat this process n times.
am i going right? it would be great if you can help me with a point of view.
kind regards and thanks for advance.
I would create a ViewGroup, then add each child view to that. The reason for this is it is more flexible (as the LinearLayout inherits from the ViewGroup). Then you can loop through each view later to get their values if need be
no, you should use a ListView and put your data in an ArrayAdapter. There are lots of examples and tutorials for that.

Change fragment content when page changed, ViewPager

I have a ViewPager, that i'm populating with fragments which has a listview inside. The point is that i have to show a really big amount of data, and i need to make pages, so i only request littel amounts of data.
My problem is that i need to call an asynctask to retrieve the data when the page is changed, and fill the listview of this page, how can i do this? How can i change that listview in the onPostExecute of the task?
PS: i have used an eclipse template for tabs + swipe activity, so im not posting my code.
I'm not sure I got your problem right, but the first thing that comes to my mind, is that I would use an AsyncTaskLoader instead of a simple AsyncTask. From my (limited) experience, loaders solve a lot of problems when it comes to Fragment/Activity lifecycle/configuration changes.
Loaders guide (Android Developers)
No matter what method you are using to get the data, changing the content of the list view in page B after loading the data in page A shouldn't be much of a problem: you have plenty of options, from simply saving the data for page B in the Activity (then changing the page with setCurrentItem and intercepting the page change event with setOnPageChangeListener),
to a more elegant approach employing a SQLite database (which btw would allow you to do some caching on the results, if possible).
Oh, and let's not forget that, if you are using an implementation of the abstract class FragmentPagerAdapter you can probably pass the data directly from one page to the other, as this PagerAdapter implementation
represents each page as a Fragment that is persistently kept in the fragment manager as long as the user can return to the page.
(just use getItem(int) to get a reference to the page you need. I never tried this myself, though).
Hope this helps
EDIT I just found out that getting a reference to the current Fragment shown in the ViewPager is tricky if you are not using a FragmentPagerAdapter: if this was the root of your problem, information about how it can be done can be found here:
Update data in ListFragment as part of ViewPager
Retrieve a Fragment from a ViewPager
Communication between ViewPager and current Fragment

ViewStub - Show view with dynamic content

This may be a dumb question, so my apologies if so; I'm fairly new to Android.
But anyway - I have a working ViewStub, which is replaced by different layouts depending different situations. It's working fine with regards to showing the correct layout when I call the setLayoutResource() method, and then setVisibility to VISIBLE. However, I now need some of the content in this view that is being shows to be dynamic (i.e. I need to set it via code rather than just show a static layout).
Is this even possible? The setLayoutResource() method only takes a static layout-resource ID, but I need that layout XML file to be able to have it's TextViews contain non-static text that comes from some code that I have ready to utilize. How should this be approached if possible? I understand the concept of having a Java class, and inflating the XML to attach itself to it to update the fields, but I can't see how that relates to my code at hand, since it's simply a layout resource int I need to set for the setLayoutResource() method in ViewStub.
I can post existing code if needed, but I'm not sure it do much more than clutter up the post. For reference - All I have is a simple layout XML file with some TextViews, and then my main XML containing the ViewStub, which is part of a custom Dialog. The user is able to instantiate the Dialog and set the layout, which in turn sets the layout of the ViewStub. This is the layout in which I need the dynamic content to be used.
Any advice would be greatly appreciated. Thanks!
Turns out this wasn't too difficult to accomplish. I just needed to use the ID of the TextView layouts after inflating the ViewStub to get a copy of the actual TextViews, then I was easily able to set their text to whatever kind of dynamic/custom text I desired.
I also needed to comment out the code that shows it via the .VISIBLE call, and instead do the following (the .inflate() line of code accomplishes the same thing as setting it to VISIBLE):
View inflatedView = dialog.myStubView.inflate();
TextView myTextView = (TextView) inflatedView.findViewById(R.id.my_text_view);
myTextView.setText("Dynamic/Custom Text");

Categories