0

I want to load data from server and show in my application (RecyclerView), for this job, when the application starts it shows 10 posts and when scrolling recyclerView show another post .

I want when users click on Favorite button, save this and when go to Favorite page show this items!
My items loaded from server (json) but and I want save favorite items in android device not server!

I want save items (posts) ID and when go to favorite page, fetch posts from server.

How can I do it?

I am amateur please help me. Thanks all

Community
  • 1
  • 1
  • You need to store favorite id in SQLite and when you want you can get eailsy from SQLite. – Arpit Patel Sep 18 '16 at 05:25
  • @ArpitPatel, can you send me code or website link? I know how to save into `SQLite db`, but I don't know how can I fetch this and send this ID's Toward server and show They on `RecyclerView` ?! –  Sep 18 '16 at 05:31
  • http://www.tutorialspoint.com/android/android_sqlite_database.htm hereis the good tutorial for SQLite and fetch column using this http://stackoverflow.com/questions/903343/cursor-get-the-field-value-android – Arpit Patel Sep 18 '16 at 05:40
  • @user6761472 as mentioned below you should save the favorite items of users in the server itself, that way if the user install your app on another device or reinstall the app the favorite items will be still available. – RamithDR Sep 18 '16 at 06:05
  • @RamithDR, Yes I know this, but I should save in device. can you help me? –  Sep 18 '16 at 06:59
  • @user6761472 If you want to save to the device locally, you should look into saving the favourites in a SQLite Database. When a user click on "Add to favourites" button, fetch the item ID and store it in the db. If you're not familiar with SQLite I recommend you look into some learning resources on Google and start with basics and work your way up. – RamithDR Sep 18 '16 at 07:09

2 Answers2

0

Add a on click listener to your RecyclerView and whenever user clicks the favorite button save the post on the user's phone offline. Using a database. Here is a simple example using SugarORM, You can use Sqlite too.

Create an Object called Post

    public class Post extends SugarRecord {
       String title;
       String content;

       public Post(){}

      public Post(String title, String content){
         this.title = title;
         this.content = content;
      }
    } 

In your onClick method :-

Post post = new Post(title,content);
post.save();

Retrieve your data in form of a list to send to adapter :-

List<Post> posts = Post.listAll(Post.class);
Sukrit Kumar
  • 375
  • 4
  • 20
0

you can store favorite items in Local Database (SQLite DB) or if you are using REST API then you can send favorite items to server.

Learn Pain Less
  • 2,274
  • 1
  • 17
  • 24