Bu derste sqlite konusu anlatılırken kullanılacak örnek uygulamanın arayüzünü kaba taslak hazırlamaya devam ediyoruz.
Bir önceki derste ve bu derste yazılan tüm kodlar aşağıdaki gibidir.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="emrealtunbilek.com.notdefterim.KategoriActivity"> <EditText android:id="@+id/etKategoriAdi" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginTop="16dp" android:ems="10" android:hint="Kategori Adını Yazın" android:inputType="textPersonName" android:text="" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:text="Yeni" android:drawableTop="@android:drawable/ic_menu_add" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/etKategoriAdi" android:layout_marginStart="16dp" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginTop="16dp" android:text="Kaydet" android:drawableTop="@android:drawable/ic_menu_save" app:layout_constraintHorizontal_bias="0.073" app:layout_constraintLeft_toRightOf="@+id/button" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/etKategoriAdi" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginTop="16dp" android:text="Sil" android:drawableTop="@android:drawable/ic_menu_delete" app:layout_constraintLeft_toRightOf="@+id/button2" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/etKategoriAdi" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" /> <ListView android:layout_width="352dp" android:id="@+id/lvKategoriListesi" android:layout_height="wrap_content" android:layout_marginLeft="32dp" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:entries="@array/notlar" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/button2" android:layout_marginRight="32dp" app:layout_constraintRight_toRightOf="parent" /> </android.support.constraint.ConstraintLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="emrealtunbilek.com.notdefterim.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" app:fabSize="normal" android:layout_margin="@dimen/fab_margin" app:srcCompat="@drawable/yeni_not" /> </android.support.design.widget.CoordinatorLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="emrealtunbilek.com.notdefterim.NotActivity"> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="16dp" android:entries="@array/kategoriler" app:layout_constraintHorizontal_bias="0.0" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" /> <EditText android:id="@+id/etNot" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginTop="16dp" android:ems="10" android:inputType="textPersonName" android:text="" android:hint="Not Yaz" app:layout_constraintHorizontal_bias="0.504" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/spinner" /> </android.support.constraint.ConstraintLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="emrealtunbilek.com.notdefterim.NotActivity"> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="16dp" android:entries="@array/kategoriler" app:layout_constraintHorizontal_bias="0.0" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" /> <EditText android:id="@+id/etNot" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginTop="16dp" android:ems="10" android:inputType="textPersonName" android:text="" android:hint="Not Yaz" app:layout_constraintHorizontal_bias="0.504" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/spinner" /> </android.support.constraint.ConstraintLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
package emrealtunbilek.com.notdefterim; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; public class KategoriActivity extends AppCompatActivity { ListView kategoriListesi; EditText kategoriAdi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_kategori); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); kategoriListesi= (ListView) findViewById(R.id.lvKategoriListesi); kategoriAdi= (EditText) findViewById(R.id.etKategoriAdi); kategoriListesi.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String tiklanilanKategori= (String) kategoriListesi.getItemAtPosition(position); kategoriAdi.setText(tiklanilanKategori); } }); } @Override public boolean onSupportNavigateUp() { onBackPressed(); return super.onSupportNavigateUp(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
public class MainActivity extends AppCompatActivity { Spinner spinner; ListView notlarListesi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); spinner = (Spinner) findViewById(R.id.spinner); notlarListesi = (ListView) findViewById(R.id.lvNotlar); String[] notlar = getResources().getStringArray(R.array.notlar); ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.notlar_tek_satir, R.id.tvNot, notlar); notlarListesi.setAdapter(adapter); notlarListesi.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, NotActivity.class); String tiklanilanNot = (String) notlarListesi.getItemAtPosition(position); intent.putExtra("notIcerik", tiklanilanNot); startActivity(intent); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, NotActivity.class); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } if (id == R.id.action_kategori) { Intent intent = new Intent(this, KategoriActivity.class); startActivity(intent); return true; } return super.onOptionsItemSelected(item); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
package emrealtunbilek.com.notdefterim; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.EditText; public class NotActivity extends AppCompatActivity { EditText not; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_not); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); not= (EditText) findViewById(R.id.etNot); Intent intent=getIntent(); if(intent!=null){ String tiklanilanNot=intent.getStringExtra("notIcerik"); not.setText(tiklanilanNot); } } @Override public boolean onSupportNavigateUp() { onBackPressed(); return super.onSupportNavigateUp(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_height="wrap_content" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/imageView" android:layout_width="32dp" android:layout_height="32dp" android:tint="@color/colorAccent" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginStart="14dp" android:layout_marginTop="13dp" app:srcCompat="@android:drawable/ic_menu_edit" /> <TextView android:id="@+id/tvNot" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignTop="@+id/imageView" android:layout_marginStart="20dp" android:layout_toEndOf="@+id/imageView" android:text="TextView" android:textSize="18sp" /> </RelativeLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="emrealtunbilek.com.notdefterim.MainActivity" tools:showIn="@layout/activity_main"> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="16dp" android:entries="@array/kategoriler" app:layout_constraintHorizontal_bias="0.0" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" /> <ListView android:id="@+id/lvNotlar" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/notlar" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="@+id/spinner" android:layout_marginLeft="32dp" android:layout_marginRight="32dp" /> </android.support.constraint.ConstraintLayout> |