How to show an Android Toast message from a fragment

Category: 

This is how you can show an Android Toast message from a Fragment:

Toast.makeText(getActivity(), "Click!", Toast.LENGTH_SHORT).show();

As shown, don’t forget to call .show() at the end of the makeText method. Forgetting to call show() is a common mistake.

If it helps to see this in more context, this is a complete onListItemClick method from a ListFragment subclass I’m currently working on:

Tags: 
Tags: 
Tags: 
Tags: 
Tags: 
Tags: 

Android Studio on Mac OS X - Unable to find a valid JVM

After doing a little research, it looks like the creators of Android Studio made a quirky decision to want to enforce the use of Java 6 on Mac OS X platforms, presumably to have better font rendering. They did this by putting 1.6* in their Info.plist file instead of 1.6+ (and they’ve done this in more than one version of Android Studio. This image (from this link) shows the suggested way to fix the problem, but you can also edit the Info.plist file to solve the problem.

Living with dementia/Alzheimer's, and fear (a story about having a concussion)

Back in 2009 I had a concussion. At some point after that I drove to Illinois to see my family. I was tired after the drive and fell asleep on my sister’s couch, only to be awakened by a loud noise. I opened my eyes and looked in the direction of the noise. A woman standing in the kitchen looked at me and said, “I’m sorry, did I wake you?”

I replied, “Um, that’s okay, no problem.” I didn’t know who the woman was, but she seemed nice, and really sorry for having made the noise.

After she turned and walked away I looked around; I didn’t know where I was. My first instinct was to panic, but I tried not to. I thought hard, “Where am I? Who is that woman?” I’m sure that I also thought, “Who am I?,” but as I write this I remember those first two questions the most.

After at least ten seconds of trying to control my panic and search my memory, it finally came back to me. I was Al, the woman was my mother, and I was at my sister’s house. The panic subsided.

(I write this because of a dream this morning, and because I can only begin to imagine the fear that people with dementia/Alzheimer’s must deal with on a regular basis.)

Syndicate content