Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

int java android example


int occupy 4 bytes (32 bits) in memory

int in Java example of using Integer and Array of Integer and Iteger to String

        // get max end min values of int in Java example 4 bytes (32 bits) PC architecture
	System.out.println(Integer.MAX_VALUE); // 2147483647
	System.out.println(Integer.MIN_VALUE); // -2147483648

// members variable
private int mProgress = 10;

//integer to string java
int myInteger = 8;
String myString = Integer.toString(myInteger);

// a final variable can only be initialized once
static final int NUM_PARTICLES = 15;

 for (int i = 0; i < NUM_PARTICLES ; i++) { 
// do something

// int as return value of function
public int getCount() {
return 5;

// int as a parametr of function
public float getFloatFromInt(int i) {
float fRet = (float) i;
 return fRet;

//array of int
int[] anArray;              // declares an array of integers
          anArray = new int[2];      // allocates memory for 2 integers
          anArray[0] = 100; // initialize first element
          anArray[1] = 200; // initialize second element

for (int i = 0; i < anArray.length; i++) {
// print out values from anArray
System.out.println("Index: " + i);
System.out.println("Value: " + anArray[i]); 

397LW NO topic_id


Další témata ....(Topics)


On orientation changed view button textview not visible Android | on-orientation-changed-view-button-textview-not-visible-android

Try add to AndroidManifest.xml configChanges for your Activity

 <activity android:name=".MainActivity"

Force Screen On - dont use WakeLock - use getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - Android sample | force-screen-on-dont-use-wakelock-use-getwindow-addflagswindowmanager-layoutparams-flag_keep_screen_on-android-sample

FLAG_KEEP_SCREEN_ON saving energy. Protects the battery if a user closing applications using the Return button on device. The device will returned to user screen mode settings.

    protected void onCreate(Bundle icicle) {

Class File Editor - Source not found - Change Attached Source - Eclipse | class-file-editor-source-not-found-change-attached-source-eclipse

The source attachment does not contain the source for the file TextWatcher.class.
You can change the source attachment by clicking Change Attached Source below:

You have to add JDK src.zip path to dialog as on image below.
[caption id="attachment_1091" align="alignleft" width="282" caption="class file editor source not found Eclipse warning"][/caption]

Or go to Project > Properties > Java Build Path > Libraries
Expand JRE System Library. Expand rt.jar.
Select Source attachment and double click or Edit.
Type path the source code file (External File…) and press OK.

[caption id="attachment_1094" align="alignleft" width="300" caption="Java project build path"][/caption]

Or type path in Java JRE definition

[caption id="attachment_1105" align="alignleft" width="300" caption="Java JRE deifiniton path in Eclipse"][/caption]

How open String.class or others keywords definition with Eclipse.

Now if mouse move about keywords String or F3 on keywords and press button in yellow field will opened String.class
Java Eclipse intellisense


Who has higher priority build.gradle or AndroidManifest Android Studio | who-has-higher-priority-build-gradle-or-androidmanifest-android-studio

build.gradle in module have higher priority then AndrodiManifest.xml
Try this.
AndroidManifest.xml have code:

        android:targetSdkVersion="23" />

build.gradle have code:

   defaultConfig {
        applicationId "cz.okhelp.words"
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 107
        versionName "1.0.7"

Warning in AndroidManifest.xml:
This targetSdkVersion value (23) is not used; it is always overridden by the value specified in the Gradle build script (19) less... (Ctrl+F1)
The value of (for example) minSdkVersion is only used if it is not specified in the build.gradle build scripts. When specified in the Gradle build scripts, the manifest value is ignored and can be misleading, so should be removed to avoid ambiguity.

How are you old - date calendar age Java Android example | how-are-you-old-date-calendar-age-java-android-example

Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17); Calendar today = Calendar.getInstance(); Android example.

public class HoriziontalScrollActivity extends Activity {
	TextView txtV;
	Context cntx;
    public void onCreate(Bundle savedInstanceState) {
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        StringBuilder strBuild = new StringBuilder();

        // enter your date of birth
        Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17);
        Calendar today = Calendar.getInstance();
        int yourAge = today.get(Calendar.YEAR) - dateOfYourBirth.get(Calendar.YEAR);
        dateOfYourBirth.add(Calendar.YEAR, yourAge);
        if (today.before(dateOfYourBirth)) {
        strBuild.append("You are " + yourAge + " old!");

Editace: 2011-09-26 20:51:00
Počet článků v kategorii: 397

11 Share