Skip to content

Instantly share code, notes, and snippets.

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import java.util.ArrayList;
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(
(ListView) findViewById(R.id.list),
new SwipeDismissListViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
myList = (ListView) findViewById(R.id.list);
ImageButton fabImageButton = (ImageButton) findViewById(R.id.fab_image_button);
fabImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
list.add("New Item");
adapter.notifyDataSetChanged();
AlertDialog.Builder todoTaskBuilder = new AlertDialog.Builder(MainActivity.this);
todoTaskBuilder.setTitle("Add a List item.");
todoTaskBuilder.setMessage("Describe the item.");
final EditText todoET = new EditText(MainActivity.this);
todoTaskBuilder.setView(todoET);
<RelativeLayout android:id="@+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@android:color/white">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
android:layout_weight="1"
android:layout_margin="5dp"/>
<dimen name="fab_button_diameter">56dp</dimen>
<dimen name="fab_button_margin_bottom">16dp</dimen>
<dimen name="fab_button_margin_right">16dp</dimen>
<dimen name="elevation_low">1dp</dimen>
<dimen name="elevation_high">8dp</dimen>
private void updateTodoList() {
todoListSQLHelper = new TodoListSQLHelper(MainActivity.this);
SQLiteDatabase sqLiteDatabase = todoListSQLHelper.getReadableDatabase();
//cursor to read todo task list from database
Cursor cursor = sqLiteDatabase.query(TodoListSQLHelper.TABLE_NAME,
new String[]{TodoListSQLHelper._ID, TodoListSQLHelper.COL1_TASK},
null, null, null, null, null);
//binds the todo task list with the UI
<menu 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" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
@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.
//noinspection SimplifiableIfStatement
int id = item.getItemId();
if (id == R.id.action_settings) {
ArrayList<String> list = new ArrayList<>();
<resources>
<string name="app_name">List</string>
<string name="title_section1">List</string>
<string name="title_section2">About</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_example">Example action</string>