xtensivearts - One Leap Ahead
Episode #6 – Notification & Long Clicks

Episode #6 – Notification & Long Clicks

Posted 08/13/2009 - 1:15 am by Mathias Reisch

In this episode we will take a look at how to notify the user by using Toast messages. These messages are small, unobstrusive notifications that can be used in all kinds of different situations. They are quite elegant and very easy to use.

We will also take a second look at button listeners by introducing the OnLongClickListener. All in all we will create a nice application that is fun to play around with and that invites you to customize it in any way you like.

The Tutorial

And please, if you enjoyed this episode, share it on your favorite social networking site. Also if you have any comments or suggestions, feel free to leave a message below. You will notice that I reduced the resolution of the video. The reason for that is, that these videos are getting quite large now and not everyone has a super fast internet connection. So the smaller resolution will hopefully allow people without high-speed connection to view or download these videos without waiting ages for that download to finish. Anyway these videos are still in a very good quality even if scaled up to a much higher screen resolution when using fullscreen mode.

You can find the project files for this episode here: Episode #6 Project Files (.zip)

Related posts:
  1. Episode #9 – Lists: Item Clicks
  2. Episode #10 – Intents: An Introduction
  3. Episode #8 – The Alert Dialog
  4. Episode #11 – Intents: Multi Activity Applications
  5. Episode #3 – Using Buttons
  6. Episode #2 – Create A New Project And Run It
  7. Episode #4 – Checkboxes & Complex Layouts
  8. Episode #7 – Using Basic Lists
  9. Episode #5 – Using Radio Buttons
  10. Episode #1 – Getting Started!

Why Not Leave a Comment?

Name:*
E-Mail:*
Website:
Comment:*

Comments

Stef Dijksman

09/27/2009 – 3:00 pm

Thank you ! i will put a link to this on my website on my tutorial page! i really like to see something with making an aplication that works with google maps !!

i hope you concider it in making one!

adem

10/31/2009 – 2:19 pm

Very good tutorial.Thank you so much….

mwm

01/07/2010 – 6:47 am

Great content!
Just learned a lot!
Thank you.

Cheers from Portugal

Chris

01/29/2010 – 6:53 pm

Thanks a lot.
The tutorial is quite straight forward and easy to understand even for a beginner like me (Although not everything).
Please can you do a tutorial on using the bluetooth API to develop a remote control for laptops?
It will really be great as I have been trying something like that but kept getting stock.

matias

03/31/2010 – 5:25 am

Thank you very much Mathias! The tutorials are really great.

Aleprex

04/11/2010 – 11:18 pm

Very nice tutorial! Please go on with more videos ;)

mhor

04/23/2010 – 10:54 am

Great tutorial Mathias!

Regarding the declaration of “sum” (Based on the video), I think you need to initialize it to a default value of zero (0)

Snippet:
Integer sum = 0;

Im using Android 2.1 right now and it returns an error during this line:

Snippet:
sum += Integer.parseInt((String).b.getText());

That’s just what I’ve noticed so far. But still, you’re tutorials are great. I hope these videos are downloadable.

mhor

04/23/2010 – 11:04 am

Another thing is, there is a minor bug with the reset button (when clicked twice, button3 becomes black). So what I did to correct this is to put this code on the OnClickListener of reset button.

Snippet:

if(def.getId() == old.getId())
old.setTextColor(Color.BLACK);

Hope this helps on you guys watching this tutorial.

Thanks again Mathias! More videos please! :)

zephirus

04/24/2010 – 1:20 pm

Hi!

Your tutorials are great. Do you plan to do a tutorial for sqlite databases? It would be great. Also, a tutorial to retrieve information from the internet would be awesome.

Mathias Reisch

04/24/2010 – 9:01 pm

Hi zephirus! Thank you for your comment. You will be happy to hear that the upcoming tutorial will actually be an introduction to working with databases. Stay tuned!

Ryan

04/29/2010 – 5:13 am

“You will be happy to hear that the upcoming tutorial will actually be an introduction to working with databases. Stay tuned!”

Really?!
Oh my gosh, I’m SOOO EXCITED!!!!! :D
I can’t wait! ^_^

ChaseNYC

04/29/2010 – 6:46 am

Thank you so much for these tutorials, there are so many things I’d love to see from you but I am just happy for whatever you have time to create. It has been an immense resource to me.

I did find one small, problem with the code with a very easy solution. With this program, if you hit reset with the default already on button 3 it will remove the red text. All you have to do is switch the order in the reset button code to:

old.setTextColor(Color.parseColor(“#000000″));
def.setTextColor(Color.parseColor(“#ff0000″));

from
def.setTextColor(Color.parseColor(“#000000″));
old.setTextColor(Color.parseColor(“#ff0000″));

Hannes

05/27/2010 – 10:50 pm

indeed, chaseNYC was right to mhor’s second remark, i figured to.
mhor’s first remark has to do with the fact that the jvm initialises every int as 0,
but maybe the androids dalvik vm doesn’t, maybe for performance sake?
(String).b.getText() has one point to much, maybe that’s the solution, or you can try b.getText().toString(), wich overrides the object.toString() method
please reply why it gave the error if you found the solution :) grtz

Hannes

05/27/2010 – 11:28 pm

also one last thing, on the reset button you forgot to show the toast
;)

Stefan

06/25/2010 – 1:17 am

Hey! Thanks for these great tutorials!

But I’ve got a problem.

I just installed eclipse, android sdk and the latest java version. I’m following this tutorial, but when I’m trying to write anything in strings.xml I get this error: “An error has occurred. See error log for more details.
java.lang.NullPointerException”.

Do anyone know how to fix this?

Stefan

06/25/2010 – 11:42 am

I don’t know how. But when I open Eclipse today I don’t have any errors no more. It works perfect!

Viktor

07/04/2010 – 1:10 pm

Best tutorial out here; currently fixed this multiple thing! :D

ratso

07/17/2010 – 11:43 pm

I added the following line of code:
currentBaseNumberButtonId = b.getId();
Toast.makeText(getApplicationContext(), “Multiple value has changed to ” + currentBaseNumber + “.”, Toast.LENGTH_SHORT).show();

return true;

and now the resetting toast no longer works, is there a reason for that or did i mess up somewhere??

Kenneth

08/04/2010 – 8:42 am

This is really awsome! When can we expekt to see number 12? :D

Gerhard

08/06/2010 – 12:37 pm

Greate Tutorial, funny idea, but to clarify math. 0 * 4 = 0 and therefore this is a valid result. It is not necessary to remove this case.

Marcus.de

08/15/2010 – 9:13 pm

heyhey,

if you start coding in the “Episode6.java” you’ve forgotten to change the line:
Integer sum;
to->
integer sum = 0;

in the files you have, but not in the video ;)

greets from germany

Marcus

waqar

08/17/2010 – 7:12 pm

videos don’t work for me, i even have latest flash player installed

Mathias Reisch

08/19/2010 – 11:01 pm

Hi waqar,

I just checked and the videos seem to play just fine.

Richard L

08/25/2010 – 2:20 pm

Great example. You do a great job. I appreciate your time in putting this together and sharing it.

Razouille

08/27/2010 – 1:57 pm

Great tutorials, thanks for making them.
Little remark at the last Toast.makeText() you forgot the show()
it’s in reset.setOnClickListener.
Anyway great job thx again.

Razouille

08/27/2010 – 2:02 pm

Forget my previous comment I missed Hannes’ comment reporting the same thing.

Carl

09/15/2010 – 5:25 pm

Hey Mathias, love the work your doing. I’m having a challenge though; my challenge is that i need a sample of code that could connect me to a webserver and retrieve information and then post the updates to my application. Can you help?

Nag

11/04/2010 – 1:30 pm

This tutorial helped me a lot to learn the basics of android app development. It is very useful for beginers. Nice tutorial… Thank you.

George

11/13/2010 – 6:05 pm

Hello Mathias ! Your content is nothing short of a blessing. I am a biomedical engineer by profession. I have few ideas for apps but have been overwhelmed in the past by the tedium of actually developing it. But, u make it so simple ! ! Thank you !!

Karthick

12/09/2010 – 8:38 pm

Great Tutorial. Good One for a beginner

Dhamshaniya Hitesh l

01/18/2011 – 1:26 pm

This is really very good WebSite to learn it self. Thank to Make it.

Mario

01/19/2011 – 4:07 am

Excelente tutorial. Muy util. Excellent tutorial. Very useful.

Glad

01/23/2011 – 12:29 am

Thank you very much!!, I finally understood, what TOAST messages are and how to implemented them.!
I also like your approach and detail explanation,.
Your help is highly appreciated.!

uvok

01/30/2011 – 7:50 pm

I have to do some android programming for work and am totally new to Android programming (even to Java actually), and I think video tutorials are a really nice way of learning it.

Great work, I’ll surely stay tuned.

chuck wang

03/03/2011 – 6:33 pm

i dont get it….whats the difference between ‘Integer’ and ‘int’?
thanks

Mathias Reisch

03/05/2011 – 2:41 am

Hey Chuck,

the difference is that ‘int’ is a primitive and ‘Integer’ is a class. For a more detailed explanation you might want to have a look at this: http://mindprod.com/jgloss/intvsinteger.html

Bashara Hinnawi

03/23/2011 – 7:15 pm

Hi Maties,
Excellent videos!!!
I have one question:
Can’t lines 122-131 be replaced by a method that would imitate the Long Clicking of the number 4?

Thanks,
Bashara

Priyesh

05/30/2011 – 12:03 am

great job thank u so much Mathias Reisch!!!