Академический Документы
Профессиональный Документы
Культура Документы
-Self contained
-Serverless
-Zero-config
-Transactional
public static final class TodosEntry implements BaseColumn{ //inner class, one
for each table
Napravis novu klasu koja sadrzi sve statis final stringove sa nazivima kolona,
tabele i sl.
nakon toga imas access svemu tome, u biti lakse je radit i na ruku ti je. Plus kad
je private static final moze se koristit bez pravljenja objekta.
kroz private static final String napravis create table... create table
tabela(vrijednosti...)
Kad hoces selectovat treba ti String[] projection (kolone koje hoces da vidis),
where klauza ili ti String selection= row=?
i vrijednosti za where String[] selectionArgs = {"v1","v2"...}
CONTENT PROVIDER
Abstract classes used to manage access to a structured set of data
Content provider enables data to be shared with other apps on phone, plus it
enables that u can store different dataType and to read
Create new Java class extends ContentProvider and create required methods.
UriMatcher
Class that parses URIs and when it finds a knwon pattern, it matches them with and
int
Creating of UriMatcher
private static final int CATEGORIES=100 <- declare int to identify operations
private static final UriMatcher uriMatcher=new UriMatcher(UriMatcher.NO_MATCH); <-
konstruktor
uriMatcher.addURI(AUTHORITY,BASE_PATH,CATEGORIES); <-Setup the UriMatcher with the
Uri patterns
int match=uriMatcher.match(uri); <- call the uri matcher, returns int that
identifies operation
long id=db.insert(table_name,null,values);
Cursor loader class that queries ContentResolver and returns a Cursor loading data
asynchronously
METODE:
public TodosCursorAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return
LayoutInflater.from(context).inflate(R.layout.todo_list_item,parent,false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView todoTextView =(TextView) view.findViewById(R.id.tvText);
int textColumn =
cursor.getColumnIndex(TodosContract.TodosEntry.COLUMN_TEXT);
String text=cursor.getString(textColumn);
todoTextView.setText(text);
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
String[] projection ={
TodosEntry.COLUMN_TEXT,
TodosEntry.TABLE_NAME+"."+TodosEntry._ID,
TodosEntry.COLUMN_CREATED,
TodosEntry.COLUMN_EXPIRED,
TodosEntry.COLUMN_DONE,
CategoriesEntry.TABLE_NAME+"."+CategoriesEntry._ID,
CategoriesEntry.COLUMN_DESCRIPTION
};
return new
CursorLoader(this,TodosEntry.CONTENT_URI,projection,null,null,null);
}
i na kraju
Create new class -> Add constructor -> in InsertData methods where you have create
new object -> initialize new object and put datas in
TodosQueryHandler todosQueryHandler=new
TodosQueryHandler(this.getContentResolver());
todosQueryHandler.startInsert(1,null,TodosEntry.CONTENT_URI,values);
ili
todosQueryHandler.startDelete(1,null,TodosEntry.CONTENT_URI,values);
napravit novi package model, za svaki entitet napravit class i dodati tipove kao
final static observable
<EditText>
android:text="@={todo.text}" //ovako se koristi da se vezu podaci i da
se na svaku promjenu promjeni atribut
android:text="@{todo.text}" ovo znaci da se moze samo tekst promjenit
al ne i snimit
</layout>
Intent intent=getIntent();
todo=(Todo) intent.getSerializableExtra("todo");
ActivityTodoBinding binding= //ovo se samo kreira znas sve vrijednosti i
kako ih dodijeliti
DataBindingUtil.setContentView(this,R.layout.activity_todo);
Posto u listView-u nije moguce bind-at entries mora se napravit novi binder(class)
}
}
moras napravit male izmjene u CategoryActivity, imas masu koda pogledaj sta je
radio
posto je ovaj lik samo copy/paste imas kod moras pogledat ostatak,
fun fact
new AlertDialog.Builder(CategoryActivity.this)
.setTitle(getString(R.string.delete_categories_dialog_title))
.setMessage(getString(R.string.delete_categories_dialog))
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
//delete
categories.ItemList.remove(category);
String [] args = new String[1];
Uri uri =
Uri.withAppendedPath(TodosContract.CategoriesEntry.CONTENT_URI,
String.valueOf(category.catId.get()));
handler.startDelete(1, null, uri
, null, null);
category = null;
}})
.setNegativeButton(android.R.string.no, null).show();