我有以下类别:链接查询与境界的Android
public class Recipe extends RealmObject {
@PrimaryKey
private long id;
private String title;
private String description;
private RealmList<Ingredient> ingredients;
private String imageUrl;
}
public class Ingredient extends RealmObject{
@PrimaryKey
private long id;
private String name;
private String category;
}
我需要找到所有已通过SharedPreferences得到的成分配方。这是我要得到,我要寻找在所有配方成分的ID代码:
public RealmResults<Recipe> getRecipesByIngredients(){
SharedPreferences prefs = getContext().getSharedPreferences("INGREDIENTS_USER_FILE", Context.MODE_PRIVATE);
Map<String, ?> allEntries = prefs.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
Log.d("map values", entry.getKey() + ": " + entry.getValue().toString());
String id = entry.getValue().toString();
}
}
我不能让一个查询,从ID的列表中查找存储在所有的食谱我的数据库食谱是用所获得的成分制成的。
编辑: 这是食材的SharedPreferences的例子:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="IngredienteEspecias1">9</string>
<string name="IngredienteEspecias2">10</string>
<string name="IngredienteCarne0">12</string>
<string name="IngredienteEspecias0">0</string>
</map>
数字是食材的IDS
你怎么**的ID保存到共享偏好** – EpicPandaForce
我添加了一个我的SharedPreferences的例子。 – campanoon