Tuesday, January 20, 2015

How to enable smartphone debugging mode/development option

  • Enable USB debugging on your device.
    • On most devices running Android 3.2 or older, you can find the option under Settings > Applications > Development.
    • On Android 4.0 and newer, it's in Settings > Developer options.
      Note: On Android 4.2 and newerDeveloper options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
Android 4.2以上版本
在Build numer選項按七下以打開開發人員選項

source:

Monday, January 19, 2015

AlertDialog with an OK button

package com.example.kiosk.dialog;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

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

        DisplayDialog();
    }

    private void DisplayDialog() {
        Builder MyDialogBuilder = new AlertDialog.Builder(this);
        MyDialogBuilder.setTitle("Warning");
        MyDialogBuilder.setMessage("Hello World!");
        MyDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        MyDialogBuilder.show();
    }


========================
UIAlertView in iOS Swift

Tuesday, January 13, 2015

Toast

package com.example.kiosk.toast;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {

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

        Toast.makeText(getApplicationContext(), "Hello Android!", Toast.LENGTH_LONG).show();
    }


What is the android.widget.Toast equivalent for iOS applications?

Programming Techniques for Android Studio

Auto Import

1. Select AndroidStudio->Preferences
2. Select Editor -> Auto Import
3. Tick <Optimize imports on the fly> and <Add unambiguous imports on the fly>


Change Resource ID
1. Right click on @string/something
2. Select Refactor -> Rename
3. Type in a new name and click <Refactor>