小编Anu*_*are的帖子

我正在使用android分页库,但不是以块的形式获取数据,而是一次性获得完整的列表

ViewModel类,我们在其中使用数据源加载pagedlist.

    public class RecipeListViewModel extends ViewModel {

    public LiveData<PagedList<RecipeListPojo>> mutableLiveData;

    public void init(RecipeFrom recipeFrom, RecipeDao recipeDao) {
    mutableLiveData = new 
    LivePagedListBuilder(recipeDao.getRecipeList(),10).build();
   }
   }
Run Code Online (Sandbox Code Playgroud)

这是我的dao,我们以数据源工厂的形式获取数据.

   @Dao
   public interface RecipeDao {
   @Query("select * from recipe")
   public DataSource.Factory<Integer, RecipeListPojo> getRecipeList();
   }
Run Code Online (Sandbox Code Playgroud)

在我的RecipeListPojo里面,我创建了DiffCallBack.

   public static DiffUtil.ItemCallback<RecipeListPojo> diffCallback=new 
   DiffUtil.ItemCallback<RecipeListPojo>() {
   @Override
   public boolean areItemsTheSame(RecipeListPojo oldItem, RecipeListPojo 
   newItem) {
   return oldItem.getId()==newItem.getId();
   }

   @Override
   public boolean areContentsTheSame(RecipeListPojo oldItem, RecipeListPojo 
   newItem) {
   return oldItem.equals(newItem);
   }
   };
Run Code Online (Sandbox Code Playgroud)

在我的活动中,我通过观察者和设置我的适配器来回收页面列表.

  arrayListObserver=new Observer<PagedList<RecipeListPojo>>() {
  @Override
  public void onChanged(@Nullable PagedList<RecipeListPojo> recipePojos) {

  if(recipePojos!=null) …
Run Code Online (Sandbox Code Playgroud)

android android-room android-architecture-components

7
推荐指数
1
解决办法
1193
查看次数

从Playstore更新应用程序时我收到错误"引起:java.lang.ClassNotFoundException:android.net.ZeroBalanceHelper"

从Playstore更新应用程序时我收到错误..

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available 09-02 17:10:03.586 11866-12008/? W/System.err: java.lang.ClassNotFoundException: android.net.ZeroBalanceHelper 09-02 17:10:03.586 11866-12008/? W/System.err:     at java.lang.Class.classForName(Native Method) 09-02 17:10:03.587 11866-12008/? W/System.err:     at java.lang.Class.forName(Class.java:324) 09-02 17:10:03.587 11866-12008/? W/System.err:     at java.lang.Class.forName(Class.java:285) 09-02 17:10:03.587 11866-12008/? W/System.err:     at 
com.android.okhttp.internal.http.ZeroBalanceHelperClass.getFeatureFlagValue(ZeroBalanceHelperClass.java:39)
09-02 17:10:03.587 11866-12008/? W/System.err:     at 
com.android.okhttp.internal.http.HttpEngine.followUpRequest(HttpEngine.java:1090)
09-02 17:10:03.588 11866-12008/? W/System.err:     at 
com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:393)
09-02 17:10:03.588 11866-12008/? W/System.err:     at 
 com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:501)
09-02 17:10:03.588 11866-12008/? W/System.err:     at 
 com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
09-02 17:10:03.588 11866-12008/? W/System.err:     at 
 com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
09-02 17:10:03.588 11866-12008/? …
Run Code Online (Sandbox Code Playgroud)

android noclassdeffounderror app-update

5
推荐指数
0
解决办法
510
查看次数

在房间持久库中无法使用 like 子句

我在我的项目中使用房间持久库。我试图在查询中使用“like”子句,但我无法使用。我已经尝试过编译时 (Query) 和运行时查询 (Raw Query)。它既没有给出任何异常,也没有给出任何输出。

我尝试了以下方法,但都没有奏效:-

  1. 编译时间查询 -

    @Query("select * from recipe where type_of_diet like '%vegetarian%' ")
    public abstract DataSource.Factory<Integer, RecipeListPojo> 
    getRecipeListVeg();
    
    Run Code Online (Sandbox Code Playgroud)
  2. 原始查询 -

    @RawQuery(observedEntities = RecipeListPojo.class)
    public abstract DataSource.Factory<Integer,RecipeListPojo> 
    getAllRecipesList(SupportSQLiteQuery sqLiteQuery);
    
    String query="select * from recipe  where type_of_diet like '%vegetarian%' ";
    SimpleSQLiteQuery simpleSQLiteQuery = new SimpleSQLiteQuery(query);
    recipeDao.getAllRecipesList(simpleSQLiteQuery);
    
    Run Code Online (Sandbox Code Playgroud)

compileSdkVersion 27

使用的库 - 实现 "android.arch.persistence.room:runtime:1.1.0-beta3" annotationProcessor "android.arch.persistence.room:compiler:1.1.0-beta3"

请让我知道如何运行这些类型的查询。

android android-sqlite android-room android-architecture-components

1
推荐指数
1
解决办法
3659
查看次数