0

i have two listViews,one from an rss feed and one with data from my database (using cursor).

is that possible to create a button and just change the content of my listview?

i mean,when the user first get in my app,the listView should present the articles from rss feed,and when the user press the favorite button,the list will update with the favorite articles (from the database).

menu_on_top
  • 2,613
  • 14
  • 44
  • 71

2 Answers2

0

Of course it is possible.

You need to display the button in your layout, and create a click handler to that button. The click handler should either replace the entire Fragment, the ListView, or simply replace the data in the ListView. Generally I would recommend replacing the Fragment.

You can follow this guide on how to handle input events and creating click handlers:

http://developer.android.com/guide/topics/ui/ui-events.html

To replace a ListView:

ViewGroup containerOfListView = (ViewGroup)findViewById(R.id.parent);
containerOfListView.removeAllViews();
containerOfListView.addView(newListView);
tbkn23
  • 5,205
  • 8
  • 26
  • 46
  • hello again tbkn!there is no problem that the first list is from rss feed and the second would be from a database? – menu_on_top Apr 20 '13 at 14:44
  • Not if you have them in separate fragments, or create a new ListView and remove the other. – tbkn23 Apr 20 '13 at 14:45
  • yes,the second way should fit better in my app. i have a new listview.how i will replace the two listviews?my second listview must extend cursoradapter because i'm using a cursor to get the data – menu_on_top Apr 20 '13 at 14:46
  • modified answer with sample code. You need to find the view that contains the listview (add a FrameLayout for example if you didn't have one), then clear all its views, and add the new ListView – tbkn23 Apr 20 '13 at 14:50
  • the two listView must be in the same .xml layout? – menu_on_top Apr 20 '13 at 14:57
  • no, you can use any ListView object to replace the previous ListView. – tbkn23 Apr 20 '13 at 14:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28564/discussion-between-androidde-and-tbkn) – menu_on_top Apr 20 '13 at 14:59
0

You're probably looking for one way to filter your list view, since clearing the whole list view and adding data from the cursor ain't an efficient solution, For filtering a list view you can customize your own listview's filter: Check these posts: 1 2

Community
  • 1
  • 1
Daniel Conde Marin
  • 7,588
  • 4
  • 35
  • 44