Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 668

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 668

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 668

Deprecated: Return type of WP_Theme::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 554

Deprecated: Return type of WP_Theme::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 595

Deprecated: Return type of WP_Theme::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 535

Deprecated: Return type of WP_Theme::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 544

Deprecated: Return type of WP_REST_Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 960

Deprecated: Return type of WP_REST_Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 980

Deprecated: Return type of WP_REST_Request::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 992

Deprecated: Return type of WP_REST_Request::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 1003

Deprecated: Return type of WP_Block_List::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 151

Deprecated: Return type of WP_Block_List::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 175

Deprecated: Return type of WP_Block_List::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 164

Deprecated: Return type of WP_Block_List::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 186

Deprecated: Return type of WP_Block_List::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 138

Deprecated: Return type of WP_Block_List::offsetExists($index) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 75

Deprecated: Return type of WP_Block_List::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 89

Deprecated: Return type of WP_Block_List::offsetSet($index, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 110

Deprecated: Return type of WP_Block_List::offsetUnset($index) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 127

Deprecated: Return type of WP_Block_List::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 199

Deprecated: Creation of dynamic property Automattic\Jetpack\Connection\Manager::$error_handler is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-manager.php on line 91

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Instagram_Gallery::$is_wpcom is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php on line 23

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Mailchimp::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-mailchimp.php on line 17

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Tweetstorm_Gather::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-tweetstorm-gather.php on line 21

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Tweetstorm_Gather::$is_wpcom is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-tweetstorm-gather.php on line 22

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Gutenberg_Available_Extensions::$wpcom_is_site_specific_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/gutenberg-available-extensions.php on line 20

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Memberships::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/memberships.php on line 23

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Memberships::$wpcom_is_site_specific_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/memberships.php on line 24

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Subscribers::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/subscribers.php on line 15

Deprecated: Creation of dynamic property Automattic\Jetpack\Sync\Queue::$random_int is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-queue.php on line 38

Deprecated: Creation of dynamic property Automattic\Jetpack\Sync\Queue::$random_int is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-queue.php on line 38

Deprecated: Creation of dynamic property WPCOM_Widget_Goodreads::$shelves is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/modules/widgets/goodreads.php on line 33

Deprecated: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in /var/www/twodee/blog/wp-includes/script-loader.php on line 348

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_classic_block is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 347

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 349

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block_side is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 350

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$panels_block is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 351

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$used_block_buttons is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 354

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198
» leggitns Homework 2: When Click Listeners Strike Back (TaskMan)

teaching machines

leggitns Homework 2: When Click Listeners Strike Back (TaskMan)

October 19, 2011 by . Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
cs491 mobile, fall 2011, postmortems.


Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 3030

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/class.jetpack.php on line 4255

Deprecated: Creation of dynamic property Jetpack_Carousel::$localize_strings is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 339

As you may gather from the title, click listeners were acting up in my project.

 

The intent of this project was to create a very simple Task Tracker that would allow users to use a list view to see a list of tasks, click a task to get deeper details and to edit the task, and provide a checkbox, that while not having any real functionality, allows users to mark of tasks they consider complete.  Because my previous assignment also used databases and a list view I went with a somewhat simple route this application.

And then it all went horribly wrong.

After completing a majority of my coding I went to run through the program and ran into an bug.  The click listener failed to function.  Clicking my “add new task” tab simply did nothing.  It just sat there.  I honestly don’t know what went wrong here.

 

This is the main activity for the project, as you should note, it is (very) similar to how the Rattler application was set up.

 

package edu.uwec.cs.leggitns;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends ListActivity implements OnItemClickListener {

    private static int REQUEST_CHANGE = 123;

    private TaskDatabase db;
    private ArrayAdapter<Task> adapter;
    private Task updatedTask;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        db = ((TaskManApplication) getApplication()).getTaskDatabase();

        updatedTask = null;
        adapter = new TaskAdapter(this);
        adapter.add(new Task("Add new task", null));
        Task[] tasks = db.getTasks();
        for (Task task : tasks) {
            adapter.add(task);
        }

        setListAdapter(adapter);
        getListView().setOnItemClickListener(this);
    }

    

    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Toast.makeText(this, position + "", Toast.LENGTH_SHORT).show();

        if (position == 0) {
            addNewTask();
        } else {
            Task updatedTask = adapter.getItem(position);
            Intent intent = new Intent(this, TaskActivity.class);
            intent.putExtra("taskId", updatedTask.getId());
            startActivityForResult(intent, REQUEST_CHANGE);
        }
    }
    

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CHANGE) {
            Task newVersion = db.getTask(updatedTask.getId());
            updatedTask.setTitle(newVersion.getTitle());
            updatedTask.setDetails(newVersion.getDetails());
            adapter.notifyDataSetChanged();
        }
    }

    private void addNewTask() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle("New Task");
        final EditText titleBox = new EditText(this);
        titleBox.setHint("title");
        dialog.setView(titleBox);
        final EditText detailsBox = new EditText(this);
        detailsBox.setHint("add details here");
        dialog.setView(detailsBox);
        dialog.setPositiveButton("Create",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Task task = new Task(titleBox.getText().toString(),
                                detailsBox.getText().toString());
                        long id = db.insert(task);
                        task.setId(id);
                        adapter.add(task);
                    }
                });
        dialog.show();

    }
}

 

Unfortunately because I can’t quite figure out why the click listener is acting up, I’m left with a nearly completed project that simply doesn’t work.  In addition to the main activity, I have a simple activity used for viewing the task, and an activity for editing the task (once again modeled after the editing in the Rattler app).  Because I got a late start on this project (I really should get on these much sooner) I didn’t implement such things like deleting a task, creating multiple task lists (ie. completed list and incomplete list), among other features.  And simply for the sake of showing that I did indeed have code structured for other things I’ll include a few code snippets after this paragraph.

 

package edu.uwec.cs.leggitns;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TaskActivity extends Activity{
    
    private Task task;
    private TaskDatabase db;
    
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.task);
        
        long id = getIntent().getLongExtra("taskId", -1);
        
        db = ((TaskManApplication) getApplication()).getTaskDatabase();
        task = db.getTask(id);
        
        TextView titleText = (TextView) findViewById(R.id.taskTitle);
        titleText.setText(task.getTitle());
        
        TextView detailsText = (TextView) findViewById(R.id.taskDetails);
        detailsText.setText(task.getDetails());
        
        Button editButton = (Button) findViewById(R.id.editButton);
        editButton.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), EditActivity.class);
                intent.putExtra("taskId", task.getId());
            }

            
        });
    }
    
    
}
package edu.uwec.cs.leggitns;

import android.app.Application;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TaskDatabase {
    
    private static String DB_NAME = "tasks.db";
    private static int DB_VERSION = 234;
    private static String TABLE_TASKS = "tasks";
    private static String COLUMN_TASKS_ID = "_id";
    private static String COLUMN_TASKS_TITLE = "title";
    private static String COLUMN_TASKS_DETAILS = "details";
    
    private SQLiteDatabase db;
    
    /**
     * Private constructor used because of singleton pattern
     * @param context
     */
    private TaskDatabase(Context context) {
        OpenHelper helper = new OpenHelper(context, DB_NAME, DB_VERSION);
        db = helper.getWritableDatabase();
    }
    
    
     private static TaskDatabase soleInstance = null;  
    
     /**
      * Public method to return the single instance of the database, creates an instance if one does not exist currently
      * @param app
      * @return TaskDatabase
      */
     public static TaskDatabase getDatabase(Application app) {
        if (soleInstance == null) {
          soleInstance = new TaskDatabase(app);
        }
        return soleInstance;
      }
      
     /**
      * Method to pull a single Task from the database
      * @param id
      * @return Task
      */
      public Task getTask(long id){
          String[] columns = {
                  COLUMN_TASKS_ID,
                  COLUMN_TASKS_TITLE,
                  COLUMN_TASKS_DETAILS          
          };
          Cursor cursor = db.query(TABLE_TASKS, columns, COLUMN_TASKS_ID + " = ?", new String[] {"" + id}, null, null, null);
          
          Task task = null;
          if(cursor.moveToNext()){
              task = new Task(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
          }
          
          return task;
      }
      
      /**
       * Method to pull out all the tasks in the database
       * @return Task[]
       */
      public Task[] getTasks(){
          String[] columns = {
                  COLUMN_TASKS_ID,
                  COLUMN_TASKS_TITLE,
                  COLUMN_TASKS_DETAILS          
          };
          Cursor cursor = db.query(TABLE_TASKS, columns, null, null, null, null, null);
          
          Task[] tasks = new Task[cursor.getCount()];
          int i = 0;
          while(cursor.moveToNext()){
              tasks[i] = new Task(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
              i++;
          }
          
          return tasks;
      }
    
      /**
       * Method to insert a new task into the database
       * @param task
       * @return
       */
      public long insert(Task task) {
            ContentValues map = new ContentValues();
            map.put(COLUMN_TASKS_TITLE, task.getTitle());
            map.put(COLUMN_TASKS_DETAILS, task.getDetails());
            return db.insert(TABLE_TASKS, null, map);
          }
          
      /**
       * Method to delete a task from the database
       * @param id
       */
      public void delete(long id) {
            db.delete(TABLE_TASKS, COLUMN_TASKS_ID + " = ?", new String[]{id + ""});
          }
          
      /**
       * Method to update a task in the database
       * @param task
       * @return
       */
      public long update(Task task) {
            ContentValues map = new ContentValues();
            map.put(COLUMN_TASKS_TITLE, task.getTitle());
            map.put(COLUMN_TASKS_DETAILS, task.getDetails());
            return db.update(TABLE_TASKS, map, COLUMN_TASKS_ID + " = ?", new String[]{"" + task.getId()});
          }
    
      
      private class OpenHelper extends SQLiteOpenHelper {
          public OpenHelper(Context context,
                          String name,
                          int version) {
          super(context, name, null, version);
        }
        
        @Override
        public void onCreate(SQLiteDatabase db) {
            String q = "CREATE TABLE " + TABLE_TASKS + "(" +
                     "  " + COLUMN_TASKS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                     "  " + COLUMN_TASKS_TITLE + " TEXT NOT NULL," +
                     "  " + COLUMN_TASKS_DETAILS + " TEXT NOT NULL" +
                     ")";
          db.execSQL(q);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db,
                              int oldVersion,
                              int newVersion) {
          
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_TASKS);
               onCreate(db);
        }
      }
}