129 views

Difference between logical operators and or Java

Basic difference remember it!!!
if(TRUE && TRUE && TRUE) return TRUE otherwise FALSE

if(FALSE || FALSE || FALSE) return FALSE otherwise TRUE

Logical operator and &&
If all conditions/operands is TRUE return TRUE, otherwise return FALSE

if( true and true and true){ 
  // return true - do something
}
int a = 6;
if(a == 6 && a == 6 ) {
 // if TRUE
 // true && true return true, do something
}
 
if(a == 6 && a == 5){
  // nothing, not attended
}else{
  // true && false return false, do something
}

Logical operator or ||
The logical OR operator (||) returns the boolean value true if either or both operands is true and returns false otherwise.
If one operands is TRUE, condition is TRUE:

if(FALSE OR FALSE OR TRUE) return TRUE
if(FALSE OR TRUE OR FALSE) return TRUE
if(FALSE OR FALSE OR FALSE) return FALSE
 
int a = 6;
if(a==6 || a==5){ // TRUE || FALSE return TRUE
  //if return TRUE
  //one from operadns is TRUE return true,  do something
}
 
if(a==5 || a==4){ // FALSE || FALSE return FALSE
 // not attended
}else{
 //if return FALSE, do something
}

rev

Posted in Android Examples Code | Tagged , | Comments Off
256 views

Import project Android Eclipse

Import a new Android project for example downloaded from internet via Eclipse into project folder.

  1. Right click into projects explorer in Eclipse and select Import
  2. Android
  3. Existing Android Code Into Workspace
  4. Root Directory (select folder of downloaded project)
  5. Check your downloaded project
  6. Check Copy project into Workspace
  7. Finish (press)
Posted in Android Examples Code, Eclipse | Tagged | Comments Off
325 views

findViewById in onCreate returns NULL when using Fragment

Call findViewById from onCreateView

public class MainActivity extends ActionBarActivity {
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
 
		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.containerMoje, new PlaceholderFragment()).commit();
		}
 
	}
 
 
	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {
		public PlaceholderFragment() {
		}
 
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			if (container == null) {
		        return null;
		    }
 
 
			 TextView mText;
			mText = (TextView)rootView.findViewById(R.id.idText);
			mText.setText("Hello from fragment_main");
 
			return rootView;
		}
	}
}

res\layout
activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/containerMoje"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="cz.okhelp.autoskola.MainActivity"
    tools:ignore="MergeRootFrame" />

fragment_main.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >
 
    <TextView
        android:id="@+id/idText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
 
</RelativeLayout>
Posted in Android Examples Code | Tagged , | Comments Off
406 views

Windows set Environment Variables – Java path

How set JAVA path to Environment Variables on Windows (7)
Select Start menu > Computer > System Properties > Advanced System Settings(properties).
Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example

 C:\Program Files\Java\jdk1.8.0_05
Posted in Eclipse | Tagged | Comments Off
515 views

Where Eclipse stored Settings and Templates Java Code

C:\documents\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs
Posted in Eclipse | Comments Off
776 views

ADT Bundle 22.6.2 have memory leak.

If I trying
android-sdk_r22.6.2-windows.zip
adt-bundle-windows-x86_64-20140321.zip
and open xml layout graphic editor and xml layout file
memory continues to grow to crashes Eclipse

https://developer.android.com/sdk/index.html

I have to install old version adt-bundle-windows-x86-20131030.zip
what working fine.
I had to delete .metadata folder in workspace if I want open old version ADT

Posted in Bugs, warnings, errors, Eclipse | Comments Off
436 views

Optimizing Eclipse for Android development

Menu: Windows – Preferences
- Under General, check ‘Always run in background’
- Under General>Appearance, Un-check ‘Enable animations’
- Under General>Appearance, select Theme: ‘Classic’
- Under Java>Editor>Content Assist, uncheck ‘Enable auto activation’
- Under General>Startup and Shutdown, disable all un-used services

- Minimize Outline window – right sidebar

- Close unused projects!

Posted in Eclipse | Comments Off
712 views

Updating Android SDK failed: “A folder failed to be moved.”

Try:
- close Eclipse and continue updating
or
- change permission of folder
or
- disable antivirus
or
- copy manually from zip packages from temp
c:\Program Files\android\sdk\temp\
c:\Program Files\android\sdk\temp\platform-tools_r19.0.1-windows.zip
c:\Program Files\android\sdk\temp\tools_r22.6.2-windows.zip
into propriety folders
or
- download all SDK package and replace old
https://developer.android.com/sdk/index.html?hl=sk

Posted in Bugs, warnings, errors, Eclipse | Comments Off
494 views

Eclipse Escape text when pasting into a string literal

Window>Preference>Java>Editor>Typing and check the “Escape text when pasting into a string literal“.
Posted in Eclipse | Tagged | Comments Off
898 views

How to set different locales in android

- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder

// for locale English is default
/MyProject/res/values 
<?xml version="1.0" encoding="utf-8"?>
<resources>
 
    <string name="app_name">App English default</string>
    <string name="action_settings">Settings English default</string>
    <string name="hello_world">Hello world</string>
 
</resources>
 
// for locale Czech (cs)
/MyProject/res/values-cs
<?xml version="1.0" encoding="utf-8"?>
<resources>
 
    <string name="app_name">Aplikace česky cs</string>
    <string name="action_settings">Nastavení česky</string>
    <string name="hello_world">Ahoj světe!</string>
 
</resources>
 
// for locale English US (r is region)
/MyProject/res/values-en-rUS
 
<?xml version="1.0" encoding="utf-8"?>
<resources>
 
    <string name="app_name">App English Us locale</string>
    <string name="action_settings">Settings English Us locale</string>
    <string name="hello_world">Hello world from USA :)</string>
 
</resources>

Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.

Posted in Android Examples Code | Tagged , | Comments Off
898 views