Android stuff to do

Starting Android Development, Creating a Todo App

This article was updated in April 2016 to reflect changes in Android

Despite many articles related to Android on SitePoint, it’s been a while since we had a real ‘beginners’ tutorials. How better to fill that gap than with a staple of beginners tutorials, the ‘To Do’ App.

Needed Software

The ingredients every Android developer needs are:

  1. Android Studio, the official Android IDE (integrated development environment ). There may be still developers using the old ADT plugin for Eclipse, but that’s not maintained anymore. IntelliJ IDEA also supports Android development, so you may use that too.
  2. The Android SDK is the toolchain that manages everything required to build an Android app. It ships with Android Studio, but if you decide to use another IDE, you’ll have to download it.

It’s useful to have an Android device so you can test the app during development. If you can’t get your hands on an Android device, you can use the default emulator or Genymotion.

Note: Android’s biggest positive and flaw is it’s flexibility. I will use a particular IDE and SDK version, if your setup is different, then settings, code and screenshots may also vary.

You will need basic Java knowledge to follow this tutorial.

Getting Started

You can find the final code for this project on GitHub.

To create a new project, open Android Studio and click Start a new Android Studio project. Name the application “TodoList”, and add your company domain, which will be the application package. There can’t be two apps on the Play Store with the same package name or called “com.example”. I will name mine com.aziflaj.todolist.

Next, pick the platforms you want to develop for. I recommend setting the minimum SDK to support API level 15 and above. This means the application will support every smartphone with Android 4.0.3 or later.

On the next screen select Empty Activity and keep the name as MainActivity.

When Android Studio finishes generating the project you have the default “Hello, World” app.

Building the View

In MainActivity.java, you should have code something like the below:

On line 11, you set the view of this activity to R.layout.activity_main , which points to a file called activity_main.xml in the /res/layout directory of the project. A view controls layout of the Android interface and looks like this:

In the main view, you will add a ListView , which will contain a ToDo item in each row. To do this, replace the TextView element with the code below:

Now you will define a list item, which will represent a task in the interface.

Create a new layout file in the /res/layout folder called item_todo.xml. You will add two elements to this file, a TextView to show the task, and a “Done” Button to delete the task. Add this code to item_todo.xml, replacing anything that is already there.

The app needs a menu item to allow user to add more tasks. Add a main_menu.xml file in the /res/menu directory with the following code:

Add the code below to the MainActivity.java file, after the onCreate method:

Android developers frequently create a TAG constant with the name of the class for logging. Add this to the beginning of the MainActivity class:

The onCreateOptionsMenu() method inflates (renders) the menu in the main activity, and uses the onOptionsItemSelected() method to react to different user interactions with the menu item(s). If you run the application, it should look something like this:

If you click the add button, you will see something like this in the Android Studio log:

Next, you will add an AlertDialog to get the task from the user when the add item button is clicked. You already know where to add the code to react to the user, so replace the logging statement with this:

Читайте также:  Главная страница хром для андроид

Now, clicking the plus button gives you this:

Enter some text and when you click the add button, the Android Studio log (“logcat”) will show something like this:

Storing and Retrieving Data

Android ships with an embedded SQLite database. The database needs a table before it can store any tasks, called “TaskTable”. Create a new db folder in the same location as MainActivity.java. Then create a new class called TaskContract with the file name TaskContract.java:

Add this code to TaskContract.java, changing the two package names appropriately.

The TaskContract class defines constants which used to access the data in the database. You also need a helper class called TaskDbHelper to open the database. Create this class in the db package and add the following code:

On lines 15 to 17 is this SQL query:

Now you need to adapt MainActivity to store data in the database. Add this code where you defined the DialogInterface.OnClickListener() for the AlertDialog ‘s add button, replacing:

This makes the whole onOptionsItemSelected() method look like:

Add a private instance of TaskDbHelper in the MainActivity class:

And initialize it in the onCreate() method:

If you run the application, you won’t see any differences in the UI, but you can check that the database is working by executing these commands on the terminal:

Note: If the two last commands don’t work for you, the SQLite3 utility is not included in most production devices, but you can install it by yourself.

Now you need to fetch all the data from the database and show it in the main view.

Replace your MainActivity.onCreate() method with this:

When you run the application, LogCat will show a list of all the tasks stored in the database. Next you will display data in the main view using an Adapter .

Get a reference to the ListView created in activity_main.xml file by adding an instance of the ListView :

Initialize the reference by adding this line of code to the onCreate() method, right after creating mHelper :

Move the code (with some changes) that was logging the tasks into a private method called updateUI() :

Add this private field to the MainActivity class:

This ArrayAdapter will help populate the ListView with the data.

If you don’t understand the updateUI() method, that’s OK. Instead of logging the tasks, add them into an ArrayList of Strings. Then check if mAdapter is created or not. If it isn’t, and mAdapter is null, create and set it as the adapter of the ListView :

If the adapter is already created (which implies that it’s assigned to the ListView ), clear it, re-populate it and notify the view that the data has changed. This means that the view will repaint on the screen with the new data.

To see the updated data, you need to call the updateUI() method every time the underlying data of the app changes. So, add it in two places:

  • In the onCreate() method, that initially shows all the data
  • After adding a new task using the AlertDialog

Deleting Tasks

After finishing a task, it should be deleted from the list.

Open the item_todo.xml layout and add this line to the Button tag:

When the button is clicked, it calls this method deleteTask() in the MainActivity class:

Now, clicking the Done button will delete the task from the list and the SQLite database.

Final Words

After writing all this code, you have a simple TodoList application, built with Java for Android. If this tutorial has got you interested in learning more, then your next step is looking through the rest of SitePoint’s Android content. Enjoy!

Источник

10 best to do list apps for Android

Staying organized is one of the toughest things to do. It’s okay if you can’t keep track of it all because most of us can’t either. That’s kind of why to do list apps exist. They can add some organization to a hectic lifestyle and keep you from forgetting important stuff. To do list apps also usually work great for stuff like grocery lists and recurring tasks like taking the garbage out every week. Those with good memory probably don’t need something like this. However, in a world where multi-tasking is an increasingly important life skill, a good to-do list app can help you keep everything in order. This is one of those apps we recommend to everyone. There are a bunch to choose from, so here are the best to do list apps for Android!

Читайте также:  Удаление android с компьютера через

We’d also like to give an honorable mention to Google Keep (Google Play link). A lot of folks use it and similar note-taking apps for short to-do lists, grocery lists, and other things that may not have a time-sensitive aspect to it. It’s perfectly reasonable for super simple stuff and it’s entirely free to use.

The best to do list apps for Android

Any.do

Price: Free / $2.99 per month / $26.99 per year

Any.do is a popular to do list app that gets the basics right. You have the usual array of tasks, sub tasks, and notes that you can add to help remind yourself of what you’re supposed to do. There is also cloud syncing so you can access your tasks on a variety of devices, including desktop, web, and tablet. It has a sleek interface and built-in support for Cal Calendar if you want to kill two birds with one stone. Any.do powerful, it’s simple, and most of its features are free. Any.do is also one of the few to do list apps with support for both Google Assistant and Amazon Alexa.

Memorigi

Price: Free / $3.99 / $1.99 per month / $15.99 per year

Memorigi is one of the newer to-do list apps. It features a beautiful Material Design UI along with a bunch of other stuff. The basic features include tasks and lists, cloud syncing, recurring tasks, notifications (reminders), and more. Some of the more unique stuff includes floating actions (like Facebook Messenger’s chat heads), integrated weather, and theming. It gets the job done and looks good doing it. The organizational structure takes a bit of time to get used to, especially if you’re used to things like Todoist, TickTick, or GTasks. The free version includes some features. There is a single $3.99 for the plus version that adds most of the basic features, and a monthly subscription for the rest of it. Most should get by fine with the free or plus versions.

Microsoft To-Do

Price: Free

Microsoft To-Do is actually a surprisingly decent to do list app. It’s by the same developers who did Wunderlist after Microsoft purchased the app a few years ago. The app can do a bunch of stuff, including syncing with your Windows desktop, reminders, recurring tasks, and the usual to do list stuff. You also get collaboration features (list and task sharing) with family or work colleagues. It had potential for years, but we think it’s finally ready for prime time. This is an excellent free to do list app option.

Taskito

Price: Free with in-app purchases / $5.99

Taskito is a to-do list app and task manager. It lets you manage your tasks, see a timeline of your planned activities, and it has niceties like planning boards, a note taking function, and calendar integration. For the most part, it gets the basics right. You can schedule tasks, repeat tasks, and set reminders as needed. You can also sync your tasks between devices. Some additional stuff includes 15 themes, support for over 10 languages, and there is no advertising. There is an a la carte style in-app purchase strategy for various features or you can pay a single price and unlock everything.

Tasks

Price: Free / $1.49

Tasks is one of the newer to do list apps. It features a gorgeous UI, plenty of customization options, and a decent set of features. Functionally, it works like most other to do list apps. You simply put in the tasks, add due dates and reminders, and complete the tasks when necessary. Some of the other features include multiple lists, a dark theme, and a simple layout. It doesn’t have more popular features like list sharing or cloud syncing. However, not everyone needs those features. It’s still very much in active development, so check the Play Store to see what’s changed between now and when we update this list again.

Читайте также:  Обои для android вертикальные ромашки

Tasks.org

Price: Free / Up to $9.99 per year

Tasks.org is actually a clone of Yahoo’s old Astrid to-do list software. It actually works pretty well. You get the usual stuff like regular tasks, recurring tasks, custom filters, and syncing with your Google Task account. Plus, you get some light theming options, support for CalDAV, and Tasker support as well. You won’t have much trouble getting around the UI, although some unique controls may take a moment to learn. The app works with an annual subscription that starts at $1 per year which undercuts most of its competitors.

TickTick

Price: Free / $2.79 per month / $27.99 per year

TickTick is another simple, but powerful to do list application. This one has the basic features along with cloud syncing so you can keep track of your tasks between devices. It also includes a tag system so you can easily sort your tasks, widgets, priority levels to differentiate more important tasks, and location reminders. The free version also comes with up to two reminders per task. If you go pro, you’ll also get improved task management, improved collaboration support, and more reminders per task. It’s another solid, simple option that can work very well. The premium version adds more features, but the free version should be more than good enough for most.

Todoist

Price: Free / $28.99 per year

Todoist is a powerful to do list app that can do pretty much whatever you need it to do. On top of its mobile apps, you can get native apps on Google Chrome (as an extension), desktop, and other places for full cross-platform support. It covers the basics and also includes offline mode, tags and inboxes for easy task sorting, Wear OS support, integration with a ton of other apps (including Google Assistant), and a unique karma system that helps you visualize how productive you’ve been. We aren’t a fan of reminders being a premium-only feature when most other to do list apps don’t do that. However, the app is otherwise functional and gorgeous.

To Do List

Price: Free / $2.99

To Do List by Splend Apps is perhaps the least inventive name of any app on the list. Thankfully, it’s not half bad. The app covers the basic to do features, including the ability to get reminders to make sure you get your stuff done. The interface is reminiscent of Wunderlist but that’s not necessarily a bad thing. It’s very clean and easy to use. You also get plenty of tertiary features like adding tasks through voice commands, widgets, and more. This is a simple to do list app for simple needs. Those looking for something more complicated may need to try another option. You can download it for free to try it out. The full version costs $2.99 and you can get it free if you use Google Play Pass.

Trello

Price: Free

Trello is a big name in the to do list game and it’s one of the few options that’s entirely free. At least for right now. It comes with all of the basic features as well as a unique, card-based interface where you create your tasks on “boards.” It also comes with Google Drive and Dropbox support, Android Wear support, collaboration features, and scaling so you can do something as simple as a grocery list or as big as a multi-person group project. The app is powerful, it looks cool, and the price tag is great for a lot of folks. It was purchased in early 2017 by Altassian. We don’t know how that’ll affect it in the long term, but right now it works the same.

If we missed any of the best to do list apps for Android, tell us about them in the comments! You can also click here to check out our latest Android app and game lists!

Thank you for reading! Try these out too:

Источник

Оцените статью