Jul 20, 2016

Load Spinner with string-array from resources xml


To define string-array in resources xml, edit values/strings.xml to add items of string-array.
<resources>
    <string name="app_name">AndroidSpinner</string>
    <string-array name="weekday">
        <item>Sunday</item>
        <item>Monday</item>
        <item>Tuesday</item>
        <item>Wednesday</item>
        <item>Thursday</item>
        <item>Friday</item>
        <item>Saturday</item>
    </string-array>
</resources>


Edit layout/activity_main.xml to add Spinner with entries to load from string-array.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.androidspinner.MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android-coding.blogspot.com"
        android:textSize="28dp"
        android:textStyle="bold" />
    <Spinner
        android:id="@+id/myspinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/weekday"/>
</LinearLayout>


MainActivity.java
package com.example.androidspinner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Spinner mySpinner = (Spinner)findViewById(R.id.myspinner);
        mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                String item = (String)adapterView.getItemAtPosition(i);
                Toast.makeText(MainActivity.this, item, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }
}

Mar 4, 2016

Get the number of processor cores available to the VM

The method Runtime.availableProcessors() returns the number of processor cores available to the VM, at least 1. Traditionally this returned the number currently online, but many mobile devices are able to take unused cores offline to save power, so releases newer than Android 4.2 (Jelly Bean) return the maximum number of cores that could be made available if there were no power or heat constraints.


package example.com.androidprocessors;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int availableProcessors = Runtime.getRuntime().availableProcessors();
        Toast.makeText(MainActivity.this,
                "Available Processors: " + availableProcessors,
                Toast.LENGTH_LONG).show();
    }
}

Jan 16, 2016

Android Textual Layout (Android Dev Summit 2015)



Recent versions of Android have significant advances in typographic sophistication, including automatic hyphenation, balanced and optimized paragraph layout, OpenType features, support for dozens of scripts around the world, and more. Raph Levien, software engineer and tech lead of Android Text on the Android UI Toolkit team, covers these capabilities and how apps can make best use of them.

View presentation slides here: https://speakerdeck.com/raphlinus/android-textual-layout


Nov 23, 2015

What’s New in Android Studio 1.5

Android Studio 1.5 is focused on delivering more stability, with most of the enhancements being made under the hood. It adds new lint checks, the ability to use short names when code-completing custom views, and the memory profiler can now help you detect some of the most commonly known causes of leaked activities.

Android Studio 1.5 is now available to download from the stable release channel.

Find out more from Android Developers Blog: http://goo.gl/oIbJHO

Nov 9, 2015

What is Cardboard

What is Cardboard and Virtual Reality. This video introduces Cardboard for developers and how to use a phone and a simple box of Cardboard to tap into a new type of immersion with virtual reality.

Watch more episodes of Cardboard here:
https://goo.gl/IAoGGs



Cardboard: How Cardboard Works

Infolinks In Text Ads