SQLite Word List App Overview
SQLite Word List App Overview
11600
WordListSQLIneractive
Hasil Program :
Code Program :
[Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="[Link]
es/android"
package="[Link]">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/
[Link]">
<activity
android:name=".EditWordActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category
android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import
[Link]
;
if (requestCode == WORD_EDIT) {
if (resultCode == RESULT_OK) {
String word = [Link](EditWordActivity.EXTRA_REPLY);
if (id == WORD_ADD) {
[Link](word);
} else if (id >= 0) {
[Link](id, word);
}
// Update the UI.
[Link]();
} else {
[Link](
getApplicationContext(),
[Link].empty_not_saved,
Toast.LENGTH_LONG).show();
}
}
}
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_edit_word);
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public WordViewHolder onCreateViewHolder(ViewGroup
parent, int viewType) { View itemView =
[Link]([Link].activity_word_item, parent,
false);
return new WordViewHolder(itemView);
}
@Override
public void onBindViewHolder(WordViewHolder
holder, int position) { WordItem current =
[Link](position);
[Link]([Link]());
// Keep a reference to the view holder for the click
listener final WordViewHolder h = holder; // needs to be
final for use in callback // Attach a click listener to the
DELETE button.
holder.delete_button.setOnClickListener(new
MyButtonOnClickListener( [Link](), null) {
@Override
public void onClick(View v ) {
// You have to get the position like this, you can't
hold a reference
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext,
[Link]); [Link](EXTRA_ID,
id);
[Link](EXTRA_POSITION, [Link]());
[Link](EXTRA_WORD, word);
@Override
public int getItemCount() {
return (int) [Link]();
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// Column names...
public static final String KEY_ID = "_id";
public static final String KEY_WORD = "word";
@Override
public void onCreate(SQLiteDatabase db) {
[Link](WORD_LIST_TABLE_CREATE);
fillDatabaseWithData(db);
// We cannot initialize mWritableDB and mReadableDB here,
because this creates an infinite
// loop of on Create being repeatedly called.
}
try {
if (mReadableDB == null) {mReadableDB =
getReadableDatabase();} cursor =
[Link](query, null);
[Link]();
[Link]([Link]([Link](KEY_ID)
));
[Link]([Link]([Link](KEY
_WORD))); } catch (Exception e) {
Log.d(TAG, "QUERY EXCEPTION! " + [Link]());
} finally {
// Must close cursor and db now that we are
done with it. [Link]();
return entry;
}
}
mNumberOfRowsUpdated = [Link](WORD_LIST_TABLE,
//table to change
values, // new values to insert
KEY_ID + " = ?", // selection criteria
for row (in this case, the _id column)
new String[]{[Link](id)}); //selection args;
the actual value of the id
} catch (Exception e) {
Log.d (TAG, "UPDATE EXCEPTION! " +
[Link]()); }
return mNumberOfRowsUpdated;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
Log.w([Link](),
"Upgrading database from version " + oldVersion + " to
" + newVersion + ", which will destroy all old data");
[Link]("DROP TABLE IF EXISTS " + WORD_LIST_TABLE);
onCreate(db);
}
}
[Link]
package [Link];
public WordItem() {}
[Link]
package [Link];
import [Link];
/**
* Instantiated for the Edit and Delete
buttons in WordListAdapter. */
public class MyButtonOnClickListener implements
[Link] { private static final String TAG =
[Link]();
int id;
String word;
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="http://
[Link]/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<[Link]
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</[Link]>
<[Link]
oatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_add_24dp"
android:focusable="true"
android:contentDescription="@string/todo" />
</[Link]>
activity_edit_word.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
ndroid" android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edit_word"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:hint="@string/hint_word"
android:inputType="textAutoComplete"
android:padding="@dimen/small_padding"
android:layout_marginBottom="@dime
n/big_padding"
android:layout_marginTop="@dimen/bi
g_padding"
android:textSize="18sp" />
<Button
android:id="@+id/button_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/teal_700"
android:onClick="returnReply"
android:text="@string/button_save"
android:textColor="@color/white" />
</LinearLayout>
activity_word_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
ndroid" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dp">
<TextView
android:id="@+id/word"
android:layout_width="match_parent"
style="@style/word_title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/delete_button"
android:layout_width="match_parent"
android:layout_height="@dimen/button_height"
android:layout_weight="2"
android:background="@color/teal_700"
android:text="@string/button_delete"
android:textColor="@color/white" />
<Button
android:id="@+id/edit_button"
android:layout_width="match_parent"
android:layout_height="@dimen/button_height"
android:layout_weight="1"
android:background="@color/teal_700"
android:text="@string/button_edit"
android:textColor="@color/white"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/teal_700" />
</LinearLayout>
WordListSQLIneractiveWithSearch
Hasil Program :
Code Program :
[Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="[Link]
es/android"
package="[Link]
search">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/
[Link]">
<activity android:name=".SearchActivity" />
<activity android:name=".EditWordActivity"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category
android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import
[Link]
gActionButton; public class MainActivity extends
AppCompatActivity {
private static final String TAG =
[Link]();
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
/**
* Inflates the menu, and adds items to the action bar
if it is present. *
* @param menu Menu to inflate.
* @return Returns true if the menu inflated.
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate([Link].menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ([Link]()) {
case [Link].action_search:
// Starts search activity.
Intent intent = new
Intent(getBaseContext(),[Link]
[Link] [Link]);
startActivity(intent);
return true;
}
return [Link](item);
}
if (requestCode == WORD_EDIT) {
if (resultCode == RESULT_OK) {
String word = [Link](EditWordActivity.EXTRA_REPLY);
if (id == WORD_ADD) {
[Link](word);
} else if (id >= 0) {
[Link](id, word);
}
// Update the UI.
[Link]();
} else {
[Link](
getApplicationContext(),
[Link].empty_word_not_saved,
Toast.LENGTH_LONG).show();
}
}
}
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_edit_word);
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* Custom view holder with a text view and two buttons.
*/
class WordViewHolder extends [Link] {
public final TextView wordItemView;
Button delete_button;
Button edit_button;
@Override
public WordViewHolder onCreateViewHolder(ViewGroup
parent, int viewType) { View itemView =
[Link]([Link].activity_word_item, parent,
false);
return new WordViewHolder(itemView);
}
@Override
public void onBindViewHolder(WordViewHolder
holder, int position) { WordItem current =
[Link](position);
[Link]([Link]());
// Keep a reference to the view holder for the click
listener final WordViewHolder h = holder; // needs to be
final for use in callback // Attach a click listener to the
DELETE button.
holder.delete_button.setOnClickListener(new
MyButtonOnClickListener( [Link](), null) {
@Override
public void onClick(View v ) {
// You have to get the position like this, you can't
hold a reference
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext,
[Link]); [Link](EXTRA_ID, id);
[Link](EXTRA_POSITION,
[Link]());
[Link](EXTRA_WORD, word);
@Override
public int getItemCount() {
return (int) [Link]();
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// Column names...
public static final String KEY_ID = "_id";
public static final String KEY_WORD = "word";
@Override
public void onCreate(SQLiteDatabase db) {
[Link](WORD_LIST_TABLE_CREATE);
fillDatabaseWithData(db);
}
try {
if (mReadableDB == null) {
mReadableDB = getReadableDatabase();
}
cursor = [Link](query, null);
[Link]();
[Link]([Link]([Link](KEY_ID)
));
[Link]([Link]([Link](KEY
_WORD))); } catch (Exception e) {
Log.d(TAG, "QUERY EXCEPTION! " + e); // Just log the
exception } finally {
// Must close cursor and db now that we are
done with it. [Link]();
return entry;
}
}
mNumberOfRowsUpdated = [Link](WORD_LIST_TABLE,
//table to change
values, // new values to insert
KEY_ID + " = ?", // selection criteria
for row (in this case, the _id column)
new String[]{[Link](id)}); //selection args;
the actual value of the id
} catch (Exception e) {
Log.d (TAG, "UPDATE EXCEPTION! " + e);
}
return mNumberOfRowsUpdated;
}
/**
* Deletes one entry identified by its id.
*
* @param id ID of the entry to delete.
* @return The number of rows deleted. Since we are
deleting by id, this should be 0 or 1.
*/
public int delete(int id) {
int deleted = 0;
try {
if (mWritableDB == null) {
mWritableDB = getWritableDatabase();
}
deleted = [Link](WORD_LIST_TABLE,
//table name KEY_ID + " =? ", new String[]
{[Link](id)}); } catch (Exception e) {
Log.d (TAG, "DELETE EXCEPTION! " +
e); } return deleted;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
Log.w([Link](),
"Upgrading database from version " + oldVersion + " to
" + newVersion + ", which will destroy all old data");
[Link]("DROP TABLE IF EXISTS " + WORD_LIST_TABLE);
onCreate(db);
}
}
[Link]
package [Link];
public WordItem() {}
[Link]
package [Link];
import [Link];
/**
* Instantiated for the Edit and Delete
buttons in WordListAdapter. */
public class MyButtonOnClickListener implements
[Link] { private static final String TAG =
[Link]();
int id;
String word;
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_search);
mEditWordView = ((EditText)
findViewById([Link].search_word)); mTextView =
((TextView) findViewById([Link].search_result));
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="http://
[Link]/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<[Link]
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</[Link]>
<[Link]
oatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_add_24dp"
android:focusable="true"
android:contentDescription="@string/todo" />
</[Link]>
activity_edit_word.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
ndroid" android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edit_word"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:hint="@string/hint_word"
android:inputType="textAutoComplete"
android:padding="@dimen/small_padding"
android:layout_marginBottom="@dime
n/big_padding"
android:layout_marginTop="@dimen/bi
g_padding"
android:textSize="18sp" />
<Button
android:id="@+id/button_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/teal_700"
android:onClick="returnReply"
android:text="@string/button_save"
android:textColor="@color/white" />
</LinearLayout>
activity_word_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
ndroid" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dp">
<TextView
android:id="@+id/word"
android:layout_width="match_parent"
style="@style/word_title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/delete_button"
android:layout_width="match_parent"
android:layout_height="@dimen/
button_height"
android:layout_weight="2"
android:background="@color/teal_700"
android:text="@string/button_delete"
android:textColor="@color/white" />
<Button
android:id="@+id/edit_button"
android:layout_width="match_parent"
android:layout_height="@dimen/
button_height"
android:layout_weight="1"
android:background="@color/teal_700"
android:text="@string/button_edit"
android:textColor="@color/white"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/teal_700" />
</LinearLayout>
activity_search.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
ndroid" android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/search_word"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:hint="@string/hint_word"
android:inputType="textAutoComplete"
android:padding="@dimen/small_padding"
android:layout_marginBottom="@dime
n/big_padding"
android:layout_marginTop="@dimen/bi
g_padding"
android:textSize="18sp" />
<Button
android:id="@+id/button_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/teal_700"
android:onClick="showResult"
android:text="@string/button_search"
android:textColor="@color/white" />
<TextView
android:id="@+id/search_result"
android:layout_width="match_parent"
android:layout_height="300dp"
android:textSize="18sp"
android:hint="@string/search_results"/>
</LinearLayout>
Hasil Program :
Code Program :
Hasil Program :
Code Program :