dodawanie i pobieranie notatki do bazy
This commit is contained in:
parent
fb203f9bb6
commit
6ba51b80d1
@ -75,6 +75,6 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return super.getItemViewType(position);
|
||||
return position;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||
public interface NoteDao {
|
||||
|
||||
@Query("SELECT * FROM note_table")
|
||||
LiveData<List<NoteEntity>> getNotes();
|
||||
List<NoteEntity> getNotes();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
void insert(NoteEntity noteEntity);
|
||||
|
@ -5,6 +5,7 @@ import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Random;
|
||||
|
||||
/*
|
||||
@ -14,7 +15,7 @@ https://developer.android.com/codelabs/android-room-with-a-view#4
|
||||
*/
|
||||
|
||||
@Entity(tableName = "note_table")
|
||||
public class NoteEntity {
|
||||
public class NoteEntity implements Serializable {
|
||||
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id")
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.example.notatkon;
|
||||
package com.example.notatkon.note;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
@ -8,11 +8,11 @@ import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.notatkon.database.NoteEntity;
|
||||
import com.example.notatkon.R;
|
||||
import com.example.notatkon.entities.NoteEntity;
|
||||
import com.example.notatkon.database.NoteRoomDatabase;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -31,6 +31,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
REQUEST_CODE_NEW_NOTE
|
||||
);
|
||||
});
|
||||
|
||||
getAllNotes();
|
||||
}
|
||||
|
||||
//Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
@ -103,14 +105,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
*/
|
||||
|
||||
//pobranie notatek z bazy i wyswietlanie na ekranie
|
||||
private void getNotes() {
|
||||
private void getAllNotes() {
|
||||
|
||||
class GetNotesTask extends AsyncTask<Void, Void, List<NoteEntity>> {
|
||||
|
||||
@Override
|
||||
protected List<NoteEntity> doInBackground(Void... voids) {
|
||||
//return null;
|
||||
return (List<NoteEntity>) NoteRoomDatabase
|
||||
return NoteRoomDatabase
|
||||
.getNoteRoomDatabase(getApplicationContext())
|
||||
.noteDao().getNotes();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user