Android FAQ: How do I convert a list of strings (or a list of objects) to a single, combined string?
In Android, if you want to convert a list of strings to a String
, I just saw this approach:
Android FAQ: How do I convert a list of strings (or a list of objects) to a single, combined string?
In Android, if you want to convert a list of strings to a String
, I just saw this approach:
As a quick note Drupal programming note, here’s an example of how to write if/then/elseif/else in Drupal 8 Twig templates:
{% if node.getType == 'photo' %}
...
{% elseif node.getType in ['book', 'page'] %}
...
{% else %}
...
{% endif %}
While I’m in the neighborhood, here are a few more if
conditions I’ve written recently:
When you need to reference a drawable image from an Android XML file, such as a layout or menu file, use this tag:
android:src="@drawable/myimage"
That assumes that you have a file named myimage.png in your res/drawable directories. As a more complete example, this shows how I reference an image named images_show.png in an Android menu item:
As a brief note today, I was recently looking for all Messages/iMessage files that are stored on my Mac, and I used this shell script to copy all of those files — many of which have the same name — into a directory named tmpdir, giving them all new names during the copy process:
count=1 for i in `cat myfiles` do fname=`basename $i` cp $i tmpdir/${count}-${fname} count=`expr $count + 1` done
Without much introduction or discussion, here’s a Scala example that shows how to read from one text file while simultaneously writing the uppercase version of the text to a second output file:
As a quick note, if you’re interested in using the IO monad described in this IO Monad for Cats article, here’s the source code for a complete Scala App
based on that article:
If you ever need to copy text (or a text file) from the MacOS Terminal to the Mac clipboard, I can confirm that the macOS pbcopy
command works. It reads from STDIN and copies the text to the clipboard, so commands like these work:
$ echo "foo bar baz" | pbcopy $ cat /etc/passwd | pbcopy
If you ever need to get the “cleaned” HTML as a String
from the Java HTMLCleaner project, I hope this example will help:
Without any explanation, these are some of my working notes from my upcoming book on Scala and Functional Programming about a) for
expressions, b) map
, c) flatMap
, d) Option
, and e) nested flatMap
and map
calls.
this:
val y = x.map(_ * 2)
and this:
As a quick note, if you ever need to fill/populate a Scala list with the same element X number of times, one solution is to use the fill
method that’s available to Scala sequences, like this:
scala> val x = List.fill(3)("foo")
x: List[String] = List(foo, foo, foo)
If you want to populate a list with different element values, another approach is to use the tabulate
method:
I may explain this more in the future, but for now, here’s some source code for an example of how to use Quicklens in a Scala functional programming project.
Given some model/ADT definitions like this:
The source code below corresponds to an article I wrote titled, Android ActionBar example: How to create an options menu item.
If you need to dump the contents of an array to the Android Log (Logcat) output, I can confirm that this approach works, at least with simple arrays of integers and strings that know how to print themselves:
Log.i("MyAndroidClass", Arrays.toString(arr));
If you’re trying to print more complicated arrays of custom objects you’ll probably need to implement good toString
methods on those objects, and then this technique should work.
As a quick note, if you need some examples of the syntax of how to write a Java method that returns a generic type, I hope these are helpful:
As a quick note, here’s the source code for a Java “approximately equal” function that I use in an Android application:
If you want to hide the Android ActionBar on an Activity, it looks like there are at least two approaches.
First, add the android:theme="@android:style/Theme.NoTitleBar"
entry to the activity’s definition in AndroidManifest.xml:
<activity android:name=".PlayAGameActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar" > </activity>
A second approach is to add this code in the Activity (or Fragment) onCreate
method:
Here’s a little snippet of Android code that I want to remember:
Without much discussion, here’s an Android ListView
/ListFragment
with its Back/Up/Home button enabled:
(That button used to be a Home button, but now it’s used for the Back/Up action.)
And here’s the source code for that ListView
/ListFragment
: