Udacity – czego nauczyłam się z kursu – cz.3

SQLlite

1)      Jak stworzyć połączenie do bazy oraz proste operacje CRUD(create,read,update,delete):

https://guides.codepath.com/android/local-databases-with-sqliteopenhelper

 

tutaj po kolei wg Android Developer:

https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

 

a)       jak robić zapytania typu SELECT:

https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#query(java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String)

 

czyli w skrócie:

mDb.query(

        nazwa_tabeli,

        [‘kol1’,’kol2’],

        [‘kol1=1’],

        null,

        kolumna_group_by,

        kolumna_having,

        kolumna_order_by
);

b)      jak robić inserty

ContentValues cv=new ContentValues();

cv.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME,name);

cv.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE,partySize);


mDb.insert(WaitlistContract.WaitlistEntry.TABLE_NAME,null,cv);

 

Lub standardowo

 

        mDb.execSQL(„insert into table_name values (a,b,c));

 

c)       jak robić delete

mdB.delete (String table, 
                String whereClause, 
                String[] whereArgs)

 

Np.

         mDb.delete(WaitlistContract.WaitlistEntry.TABLE_NAME, WaitlistContract.WaitlistEntry._ID+"="+id,null)

 

https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#delete(java.lang.String, java.lang.String, java.lang.String[])

 

d)      jak obsługiwać wybieranie elementu z listy przez przesunięcie go palcem po ekranie:

 

new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT)

{


    @Override

    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {

        return false;

    }


    @Override

    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {

        long id= (long) viewHolder.itemView.getTag();

        removeGuest(id);

        mAdapter.swapCursor(getAllGuests());

    }

}).attachToRecyclerView(waitlistRecyclerView);

 

 

2)      Co zrobić w przypadku takiego błędu z Android Studio:

Plugin Error

                                               Problems found loading plugins:

                                               Plugin „Android Games” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Android NDK Support” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Android APK Support” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Google Developers Samples” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Google Cloud Tools For Android Studio” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Test Recorder” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Firebase Testing” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Google Services” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „Firebase Services” was not loaded: required plugin „Android Support” is disabled.

                                               Plugin „App Links Assistant” was not loaded: required plugin „Android Support” is disabled.

Odp:

  1. Click Ctrl+Alt+S in Windows
  2. Go to ‘Plugins’
  3. On right side it will show list of plugins and also the plugin we need, that is Android Support,check it and click Ok at the bottom of screen.

This is how it looks:

Bez tytułu.png

 

3)    Trochę tipsów i tricków do samego Android Studio

http://eagle.phys.utk.edu/guidry/android/eclipseTips.html

 

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany.