开发者

how can we include favourite functionality in android?? please provide any example

how can we include favourite 开发者_如何学编程functionality in android?? please provide any example i mean to say there is a one phase in my app "favourite". when you click on particular item from the list that particular item will be add into the favourite and you can view that selected item in that favourite list.


If I understood well you want to store favourites item somewhere. An easy way to do that could be create a key in SharedPreferences that stores you favourites.

// Read the favourites
SharedPreferences settings = context.getSharedPreferences("FavouritesApp", 0);
Set<String> favourites = setting.getStringSet("myFavourites");

// Write the favourites
SharedPreferences settings = getSharedPreferences("FavouritesApp", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putStringSet("myFavourites",myStringSet);
editor.commit();

All that you have to do is to keep a set of strings that identify your favourites.

This is a very small example and probably not the best way to do that.


As this question is somewhat linked to my problem,posting it here.

I have an android app which displays quotes and have navigation to go to next quote and so on. would like to add "Save Quote As favourite" based on users selection of particular quote.

Once user saves Fav quotes and wants to see those quotes only, app should show those quotes.

Currently app reads the quotes from XML file. Let me know if any more information is required to understand the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜