我有以下類別:鏈接查詢與境界的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