How to show data from SQLite with CRUD in Android Studio?











up vote
0
down vote

favorite












Hi I'm doing an app and I made the database but I don't know how to read it to show in a listview for example I have a table CategoriaEntradas and I need to show all the data in a listview but I don't understand very well how it works all the classes



This is my Dao class



@Dao
public interface CategoriaEntradasDao {

@Insert
void insert(CategoriaEntradas categoriaEntradas);

@Update
void update(CategoriaEntradas categoriaEntradas);

@Delete
void delete(CategoriaEntradas categoriaEntradas);

@Query("DELETE FROM CategoriaEntradas")
void deleteAll();

@Query("SELECT * FROM CategoriaEntradas")
LiveData<List<CategoriaEntradas>> getAll();

@Query("SELECT * FROM CategoriaEntradas WHERE IdCategoria =:Id")
LiveData<CategoriaEntradas> getOne(int Id);
}


This is my Entity class



@Entity(tableName = "CategoriaEntradas")
public class CategoriaEntradas {

@PrimaryKey(autoGenerate = true)
@NonNull
@ColumnInfo(name = "IdCategoria")
private Integer _idCategoria;

@NonNull
@ColumnInfo(name = "Name")
private String _name;

@NonNull
@ColumnInfo(name = "Image")
private String _image;

public CategoriaEntradas(@NonNull String name, @NonNull String image) { _name = name; _image = image;}

public void set_idCategoria(Integer _idCategoria){
this._idCategoria = _idCategoria;
}

@NonNull
public Integer getIdCategoria() {
return _idCategoria;
}

@NonNull
public String getName() {
return _name;
}

@NonNull
public String getImage() {
return _image;
}
}


My Repository class



public class CategoriaEntradasRepository {

private CategoriaEntradasDao categoriaEntradasDao;
private LiveData<List<CategoriaEntradas>> listLiveData;

public CategoriaEntradasRepository(Application application) {
Database db = Database.getDatabase(application);
categoriaEntradasDao = db.categoriaEntradasDao();
listLiveData = categoriaEntradasDao.getAll();
}

public LiveData<List<CategoriaEntradas>> getAll() {
return listLiveData;
}

public LiveData<CategoriaEntradas> getOne(int Id) {
return categoriaEntradasDao.getOne(Id);
}

public void insert (CategoriaEntradas categoriaEntradas) {
new CategoriaEntradasRepository.insertAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
}


private static class insertAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void> {

private CategoriaEntradasDao entradasDao;

insertAsyncTask(CategoriaEntradasDao dao) {
entradasDao = dao;
}

@Override
protected Void doInBackground(final CategoriaEntradas... params) {
entradasDao.insert(params[0]);
return null;
}
}

public void update(final CategoriaEntradas categoriaEntradas){
new CategoriaEntradasRepository.updateAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);

}

private static class updateAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

private CategoriaEntradasDao entradasDao;

updateAsyncTask(CategoriaEntradasDao dao) {
entradasDao = dao;
}

@Override
protected Void doInBackground(final CategoriaEntradas... params){
entradasDao.update(params[0]);
return null;
}
}

public void delete(final CategoriaEntradas categoriaEntradas) {

new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
}

public void delete(final int Id) {

final LiveData<CategoriaEntradas> categoriaEntradas = getOne(Id);
if (categoriaEntradas != null) {
new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas.getValue());
}
}

private static class deleteAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

private CategoriaEntradasDao entradasDao;

deleteAsyncTask(CategoriaEntradasDao dao) {
entradasDao = dao;
}

@Override
protected Void doInBackground(final CategoriaEntradas... params){
entradasDao.delete(params[0]);
return null;
}
}
}


And my ViewModel class



public class CategoriaEntradasViewModel  extends AndroidViewModel {

private CategoriaEntradasRepository repository;

private LiveData<List<CategoriaEntradas>> listLiveData;

public CategoriaEntradasViewModel (Application application) {
super(application);
repository = new CategoriaEntradasRepository(application);
listLiveData = repository.getAll();
}

public LiveData<List<CategoriaEntradas>> getAll() { return listLiveData; }

public LiveData<CategoriaEntradas> getOne(int Id) { return repository.getOne(Id); }

public void insert(CategoriaEntradas categoriaEntradas) { repository.insert(categoriaEntradas); }

public void update(CategoriaEntradas categoriaEntradas){ repository.update(categoriaEntradas);}

public void delete(CategoriaEntradas categoriaEntradas) {repository.delete(categoriaEntradas);}

public void delete(int Id) {repository.delete(Id);}
}









share|improve this question


























    up vote
    0
    down vote

    favorite












    Hi I'm doing an app and I made the database but I don't know how to read it to show in a listview for example I have a table CategoriaEntradas and I need to show all the data in a listview but I don't understand very well how it works all the classes



    This is my Dao class



    @Dao
    public interface CategoriaEntradasDao {

    @Insert
    void insert(CategoriaEntradas categoriaEntradas);

    @Update
    void update(CategoriaEntradas categoriaEntradas);

    @Delete
    void delete(CategoriaEntradas categoriaEntradas);

    @Query("DELETE FROM CategoriaEntradas")
    void deleteAll();

    @Query("SELECT * FROM CategoriaEntradas")
    LiveData<List<CategoriaEntradas>> getAll();

    @Query("SELECT * FROM CategoriaEntradas WHERE IdCategoria =:Id")
    LiveData<CategoriaEntradas> getOne(int Id);
    }


    This is my Entity class



    @Entity(tableName = "CategoriaEntradas")
    public class CategoriaEntradas {

    @PrimaryKey(autoGenerate = true)
    @NonNull
    @ColumnInfo(name = "IdCategoria")
    private Integer _idCategoria;

    @NonNull
    @ColumnInfo(name = "Name")
    private String _name;

    @NonNull
    @ColumnInfo(name = "Image")
    private String _image;

    public CategoriaEntradas(@NonNull String name, @NonNull String image) { _name = name; _image = image;}

    public void set_idCategoria(Integer _idCategoria){
    this._idCategoria = _idCategoria;
    }

    @NonNull
    public Integer getIdCategoria() {
    return _idCategoria;
    }

    @NonNull
    public String getName() {
    return _name;
    }

    @NonNull
    public String getImage() {
    return _image;
    }
    }


    My Repository class



    public class CategoriaEntradasRepository {

    private CategoriaEntradasDao categoriaEntradasDao;
    private LiveData<List<CategoriaEntradas>> listLiveData;

    public CategoriaEntradasRepository(Application application) {
    Database db = Database.getDatabase(application);
    categoriaEntradasDao = db.categoriaEntradasDao();
    listLiveData = categoriaEntradasDao.getAll();
    }

    public LiveData<List<CategoriaEntradas>> getAll() {
    return listLiveData;
    }

    public LiveData<CategoriaEntradas> getOne(int Id) {
    return categoriaEntradasDao.getOne(Id);
    }

    public void insert (CategoriaEntradas categoriaEntradas) {
    new CategoriaEntradasRepository.insertAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
    }


    private static class insertAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void> {

    private CategoriaEntradasDao entradasDao;

    insertAsyncTask(CategoriaEntradasDao dao) {
    entradasDao = dao;
    }

    @Override
    protected Void doInBackground(final CategoriaEntradas... params) {
    entradasDao.insert(params[0]);
    return null;
    }
    }

    public void update(final CategoriaEntradas categoriaEntradas){
    new CategoriaEntradasRepository.updateAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);

    }

    private static class updateAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

    private CategoriaEntradasDao entradasDao;

    updateAsyncTask(CategoriaEntradasDao dao) {
    entradasDao = dao;
    }

    @Override
    protected Void doInBackground(final CategoriaEntradas... params){
    entradasDao.update(params[0]);
    return null;
    }
    }

    public void delete(final CategoriaEntradas categoriaEntradas) {

    new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
    }

    public void delete(final int Id) {

    final LiveData<CategoriaEntradas> categoriaEntradas = getOne(Id);
    if (categoriaEntradas != null) {
    new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas.getValue());
    }
    }

    private static class deleteAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

    private CategoriaEntradasDao entradasDao;

    deleteAsyncTask(CategoriaEntradasDao dao) {
    entradasDao = dao;
    }

    @Override
    protected Void doInBackground(final CategoriaEntradas... params){
    entradasDao.delete(params[0]);
    return null;
    }
    }
    }


    And my ViewModel class



    public class CategoriaEntradasViewModel  extends AndroidViewModel {

    private CategoriaEntradasRepository repository;

    private LiveData<List<CategoriaEntradas>> listLiveData;

    public CategoriaEntradasViewModel (Application application) {
    super(application);
    repository = new CategoriaEntradasRepository(application);
    listLiveData = repository.getAll();
    }

    public LiveData<List<CategoriaEntradas>> getAll() { return listLiveData; }

    public LiveData<CategoriaEntradas> getOne(int Id) { return repository.getOne(Id); }

    public void insert(CategoriaEntradas categoriaEntradas) { repository.insert(categoriaEntradas); }

    public void update(CategoriaEntradas categoriaEntradas){ repository.update(categoriaEntradas);}

    public void delete(CategoriaEntradas categoriaEntradas) {repository.delete(categoriaEntradas);}

    public void delete(int Id) {repository.delete(Id);}
    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Hi I'm doing an app and I made the database but I don't know how to read it to show in a listview for example I have a table CategoriaEntradas and I need to show all the data in a listview but I don't understand very well how it works all the classes



      This is my Dao class



      @Dao
      public interface CategoriaEntradasDao {

      @Insert
      void insert(CategoriaEntradas categoriaEntradas);

      @Update
      void update(CategoriaEntradas categoriaEntradas);

      @Delete
      void delete(CategoriaEntradas categoriaEntradas);

      @Query("DELETE FROM CategoriaEntradas")
      void deleteAll();

      @Query("SELECT * FROM CategoriaEntradas")
      LiveData<List<CategoriaEntradas>> getAll();

      @Query("SELECT * FROM CategoriaEntradas WHERE IdCategoria =:Id")
      LiveData<CategoriaEntradas> getOne(int Id);
      }


      This is my Entity class



      @Entity(tableName = "CategoriaEntradas")
      public class CategoriaEntradas {

      @PrimaryKey(autoGenerate = true)
      @NonNull
      @ColumnInfo(name = "IdCategoria")
      private Integer _idCategoria;

      @NonNull
      @ColumnInfo(name = "Name")
      private String _name;

      @NonNull
      @ColumnInfo(name = "Image")
      private String _image;

      public CategoriaEntradas(@NonNull String name, @NonNull String image) { _name = name; _image = image;}

      public void set_idCategoria(Integer _idCategoria){
      this._idCategoria = _idCategoria;
      }

      @NonNull
      public Integer getIdCategoria() {
      return _idCategoria;
      }

      @NonNull
      public String getName() {
      return _name;
      }

      @NonNull
      public String getImage() {
      return _image;
      }
      }


      My Repository class



      public class CategoriaEntradasRepository {

      private CategoriaEntradasDao categoriaEntradasDao;
      private LiveData<List<CategoriaEntradas>> listLiveData;

      public CategoriaEntradasRepository(Application application) {
      Database db = Database.getDatabase(application);
      categoriaEntradasDao = db.categoriaEntradasDao();
      listLiveData = categoriaEntradasDao.getAll();
      }

      public LiveData<List<CategoriaEntradas>> getAll() {
      return listLiveData;
      }

      public LiveData<CategoriaEntradas> getOne(int Id) {
      return categoriaEntradasDao.getOne(Id);
      }

      public void insert (CategoriaEntradas categoriaEntradas) {
      new CategoriaEntradasRepository.insertAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
      }


      private static class insertAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void> {

      private CategoriaEntradasDao entradasDao;

      insertAsyncTask(CategoriaEntradasDao dao) {
      entradasDao = dao;
      }

      @Override
      protected Void doInBackground(final CategoriaEntradas... params) {
      entradasDao.insert(params[0]);
      return null;
      }
      }

      public void update(final CategoriaEntradas categoriaEntradas){
      new CategoriaEntradasRepository.updateAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);

      }

      private static class updateAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

      private CategoriaEntradasDao entradasDao;

      updateAsyncTask(CategoriaEntradasDao dao) {
      entradasDao = dao;
      }

      @Override
      protected Void doInBackground(final CategoriaEntradas... params){
      entradasDao.update(params[0]);
      return null;
      }
      }

      public void delete(final CategoriaEntradas categoriaEntradas) {

      new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
      }

      public void delete(final int Id) {

      final LiveData<CategoriaEntradas> categoriaEntradas = getOne(Id);
      if (categoriaEntradas != null) {
      new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas.getValue());
      }
      }

      private static class deleteAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

      private CategoriaEntradasDao entradasDao;

      deleteAsyncTask(CategoriaEntradasDao dao) {
      entradasDao = dao;
      }

      @Override
      protected Void doInBackground(final CategoriaEntradas... params){
      entradasDao.delete(params[0]);
      return null;
      }
      }
      }


      And my ViewModel class



      public class CategoriaEntradasViewModel  extends AndroidViewModel {

      private CategoriaEntradasRepository repository;

      private LiveData<List<CategoriaEntradas>> listLiveData;

      public CategoriaEntradasViewModel (Application application) {
      super(application);
      repository = new CategoriaEntradasRepository(application);
      listLiveData = repository.getAll();
      }

      public LiveData<List<CategoriaEntradas>> getAll() { return listLiveData; }

      public LiveData<CategoriaEntradas> getOne(int Id) { return repository.getOne(Id); }

      public void insert(CategoriaEntradas categoriaEntradas) { repository.insert(categoriaEntradas); }

      public void update(CategoriaEntradas categoriaEntradas){ repository.update(categoriaEntradas);}

      public void delete(CategoriaEntradas categoriaEntradas) {repository.delete(categoriaEntradas);}

      public void delete(int Id) {repository.delete(Id);}
      }









      share|improve this question













      Hi I'm doing an app and I made the database but I don't know how to read it to show in a listview for example I have a table CategoriaEntradas and I need to show all the data in a listview but I don't understand very well how it works all the classes



      This is my Dao class



      @Dao
      public interface CategoriaEntradasDao {

      @Insert
      void insert(CategoriaEntradas categoriaEntradas);

      @Update
      void update(CategoriaEntradas categoriaEntradas);

      @Delete
      void delete(CategoriaEntradas categoriaEntradas);

      @Query("DELETE FROM CategoriaEntradas")
      void deleteAll();

      @Query("SELECT * FROM CategoriaEntradas")
      LiveData<List<CategoriaEntradas>> getAll();

      @Query("SELECT * FROM CategoriaEntradas WHERE IdCategoria =:Id")
      LiveData<CategoriaEntradas> getOne(int Id);
      }


      This is my Entity class



      @Entity(tableName = "CategoriaEntradas")
      public class CategoriaEntradas {

      @PrimaryKey(autoGenerate = true)
      @NonNull
      @ColumnInfo(name = "IdCategoria")
      private Integer _idCategoria;

      @NonNull
      @ColumnInfo(name = "Name")
      private String _name;

      @NonNull
      @ColumnInfo(name = "Image")
      private String _image;

      public CategoriaEntradas(@NonNull String name, @NonNull String image) { _name = name; _image = image;}

      public void set_idCategoria(Integer _idCategoria){
      this._idCategoria = _idCategoria;
      }

      @NonNull
      public Integer getIdCategoria() {
      return _idCategoria;
      }

      @NonNull
      public String getName() {
      return _name;
      }

      @NonNull
      public String getImage() {
      return _image;
      }
      }


      My Repository class



      public class CategoriaEntradasRepository {

      private CategoriaEntradasDao categoriaEntradasDao;
      private LiveData<List<CategoriaEntradas>> listLiveData;

      public CategoriaEntradasRepository(Application application) {
      Database db = Database.getDatabase(application);
      categoriaEntradasDao = db.categoriaEntradasDao();
      listLiveData = categoriaEntradasDao.getAll();
      }

      public LiveData<List<CategoriaEntradas>> getAll() {
      return listLiveData;
      }

      public LiveData<CategoriaEntradas> getOne(int Id) {
      return categoriaEntradasDao.getOne(Id);
      }

      public void insert (CategoriaEntradas categoriaEntradas) {
      new CategoriaEntradasRepository.insertAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
      }


      private static class insertAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void> {

      private CategoriaEntradasDao entradasDao;

      insertAsyncTask(CategoriaEntradasDao dao) {
      entradasDao = dao;
      }

      @Override
      protected Void doInBackground(final CategoriaEntradas... params) {
      entradasDao.insert(params[0]);
      return null;
      }
      }

      public void update(final CategoriaEntradas categoriaEntradas){
      new CategoriaEntradasRepository.updateAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);

      }

      private static class updateAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

      private CategoriaEntradasDao entradasDao;

      updateAsyncTask(CategoriaEntradasDao dao) {
      entradasDao = dao;
      }

      @Override
      protected Void doInBackground(final CategoriaEntradas... params){
      entradasDao.update(params[0]);
      return null;
      }
      }

      public void delete(final CategoriaEntradas categoriaEntradas) {

      new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas);
      }

      public void delete(final int Id) {

      final LiveData<CategoriaEntradas> categoriaEntradas = getOne(Id);
      if (categoriaEntradas != null) {
      new CategoriaEntradasRepository.deleteAsyncTask(categoriaEntradasDao).execute(categoriaEntradas.getValue());
      }
      }

      private static class deleteAsyncTask extends AsyncTask<CategoriaEntradas, Void, Void>{

      private CategoriaEntradasDao entradasDao;

      deleteAsyncTask(CategoriaEntradasDao dao) {
      entradasDao = dao;
      }

      @Override
      protected Void doInBackground(final CategoriaEntradas... params){
      entradasDao.delete(params[0]);
      return null;
      }
      }
      }


      And my ViewModel class



      public class CategoriaEntradasViewModel  extends AndroidViewModel {

      private CategoriaEntradasRepository repository;

      private LiveData<List<CategoriaEntradas>> listLiveData;

      public CategoriaEntradasViewModel (Application application) {
      super(application);
      repository = new CategoriaEntradasRepository(application);
      listLiveData = repository.getAll();
      }

      public LiveData<List<CategoriaEntradas>> getAll() { return listLiveData; }

      public LiveData<CategoriaEntradas> getOne(int Id) { return repository.getOne(Id); }

      public void insert(CategoriaEntradas categoriaEntradas) { repository.insert(categoriaEntradas); }

      public void update(CategoriaEntradas categoriaEntradas){ repository.update(categoriaEntradas);}

      public void delete(CategoriaEntradas categoriaEntradas) {repository.delete(categoriaEntradas);}

      public void delete(int Id) {repository.delete(Id);}
      }






      android android-studio android-layout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 at 2:07









      Eduardo Noyola

      435




      435
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Try this at your Activity or fragment that have your listview.



          CategoriaEntradasViewModel mViewModel = ViewModelProviders.of(this).get(CategoriaEntradasViewModel.class);

          mViewModel.getAll().observe(this, new Observer<List<CategoriaEntradas>>() {

          @Override
          public void onChanged(List<CategoriaEntradas> categoriaEntradas) {

          adapter = new YourListViewAdapter(this, categoriaEntradas);
          listview.setAdapter(adapter);

          }
          }





          share|improve this answer





















          • What I have to put in YourListViewAdapter?
            – Eduardo Noyola
            Nov 14 at 3:13










          • You have to put your custom adapter there.
            – Rence Rei
            Nov 14 at 3:45










          • So I have to creat a new one?
            – Eduardo Noyola
            Nov 14 at 3:58










          • Yes, if you have custom list item view. Its similar to array adapter.
            – Rence Rei
            Nov 14 at 5:23


















          up vote
          0
          down vote













          Yes, if you have custom list item view. Its similar to array adapter.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292190%2fhow-to-show-data-from-sqlite-with-crud-in-android-studio%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Try this at your Activity or fragment that have your listview.



            CategoriaEntradasViewModel mViewModel = ViewModelProviders.of(this).get(CategoriaEntradasViewModel.class);

            mViewModel.getAll().observe(this, new Observer<List<CategoriaEntradas>>() {

            @Override
            public void onChanged(List<CategoriaEntradas> categoriaEntradas) {

            adapter = new YourListViewAdapter(this, categoriaEntradas);
            listview.setAdapter(adapter);

            }
            }





            share|improve this answer





















            • What I have to put in YourListViewAdapter?
              – Eduardo Noyola
              Nov 14 at 3:13










            • You have to put your custom adapter there.
              – Rence Rei
              Nov 14 at 3:45










            • So I have to creat a new one?
              – Eduardo Noyola
              Nov 14 at 3:58










            • Yes, if you have custom list item view. Its similar to array adapter.
              – Rence Rei
              Nov 14 at 5:23















            up vote
            0
            down vote













            Try this at your Activity or fragment that have your listview.



            CategoriaEntradasViewModel mViewModel = ViewModelProviders.of(this).get(CategoriaEntradasViewModel.class);

            mViewModel.getAll().observe(this, new Observer<List<CategoriaEntradas>>() {

            @Override
            public void onChanged(List<CategoriaEntradas> categoriaEntradas) {

            adapter = new YourListViewAdapter(this, categoriaEntradas);
            listview.setAdapter(adapter);

            }
            }





            share|improve this answer





















            • What I have to put in YourListViewAdapter?
              – Eduardo Noyola
              Nov 14 at 3:13










            • You have to put your custom adapter there.
              – Rence Rei
              Nov 14 at 3:45










            • So I have to creat a new one?
              – Eduardo Noyola
              Nov 14 at 3:58










            • Yes, if you have custom list item view. Its similar to array adapter.
              – Rence Rei
              Nov 14 at 5:23













            up vote
            0
            down vote










            up vote
            0
            down vote









            Try this at your Activity or fragment that have your listview.



            CategoriaEntradasViewModel mViewModel = ViewModelProviders.of(this).get(CategoriaEntradasViewModel.class);

            mViewModel.getAll().observe(this, new Observer<List<CategoriaEntradas>>() {

            @Override
            public void onChanged(List<CategoriaEntradas> categoriaEntradas) {

            adapter = new YourListViewAdapter(this, categoriaEntradas);
            listview.setAdapter(adapter);

            }
            }





            share|improve this answer












            Try this at your Activity or fragment that have your listview.



            CategoriaEntradasViewModel mViewModel = ViewModelProviders.of(this).get(CategoriaEntradasViewModel.class);

            mViewModel.getAll().observe(this, new Observer<List<CategoriaEntradas>>() {

            @Override
            public void onChanged(List<CategoriaEntradas> categoriaEntradas) {

            adapter = new YourListViewAdapter(this, categoriaEntradas);
            listview.setAdapter(adapter);

            }
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 14 at 2:48









            Rence Rei

            363




            363












            • What I have to put in YourListViewAdapter?
              – Eduardo Noyola
              Nov 14 at 3:13










            • You have to put your custom adapter there.
              – Rence Rei
              Nov 14 at 3:45










            • So I have to creat a new one?
              – Eduardo Noyola
              Nov 14 at 3:58










            • Yes, if you have custom list item view. Its similar to array adapter.
              – Rence Rei
              Nov 14 at 5:23


















            • What I have to put in YourListViewAdapter?
              – Eduardo Noyola
              Nov 14 at 3:13










            • You have to put your custom adapter there.
              – Rence Rei
              Nov 14 at 3:45










            • So I have to creat a new one?
              – Eduardo Noyola
              Nov 14 at 3:58










            • Yes, if you have custom list item view. Its similar to array adapter.
              – Rence Rei
              Nov 14 at 5:23
















            What I have to put in YourListViewAdapter?
            – Eduardo Noyola
            Nov 14 at 3:13




            What I have to put in YourListViewAdapter?
            – Eduardo Noyola
            Nov 14 at 3:13












            You have to put your custom adapter there.
            – Rence Rei
            Nov 14 at 3:45




            You have to put your custom adapter there.
            – Rence Rei
            Nov 14 at 3:45












            So I have to creat a new one?
            – Eduardo Noyola
            Nov 14 at 3:58




            So I have to creat a new one?
            – Eduardo Noyola
            Nov 14 at 3:58












            Yes, if you have custom list item view. Its similar to array adapter.
            – Rence Rei
            Nov 14 at 5:23




            Yes, if you have custom list item view. Its similar to array adapter.
            – Rence Rei
            Nov 14 at 5:23












            up vote
            0
            down vote













            Yes, if you have custom list item view. Its similar to array adapter.






            share|improve this answer

























              up vote
              0
              down vote













              Yes, if you have custom list item view. Its similar to array adapter.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Yes, if you have custom list item view. Its similar to array adapter.






                share|improve this answer












                Yes, if you have custom list item view. Its similar to array adapter.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 at 4:57









                Rence Rei

                363




                363






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292190%2fhow-to-show-data-from-sqlite-with-crud-in-android-studio%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?