Okhelp.cz

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.

long in java example


AD MOB

Android development

long is 64 bit signed type and used when int is not large enough to hold the value.

long je celé číslo 64 bitů -9223372036854775808 +9223372036854775807 a používá se tam, kde typ int není schopen pojmout takovou hodnotu čísla.


		// declaration and assignment of value type long
		long n = 22337203685477580L;
		// print formated value
		System.out.printf("The value of x is %d%n", n); // 22337203685477580
		System.out.format("%+,8d%n%n", n); // +22 337 203 685 477 580

		// declaring more variables in single statement
		long lo1 = 12L, lo2 = 56, lo3 = 1455555555589L;

		// long range of value
		System.out.println(Long.MAX_VALUE); // 9223372036854775807
		System.out.println(Long.MIN_VALUE); // -9223372036854775808

		// check if a string is a valid number in Java example
		// convert string to long Java example
		String sLong = "1288888888888888";
		long longParse = Long.parseLong(sLong);

		// convert strings to numbers
		long longFromString = (Long.valueOf(sLong)).longValue();

		// long to string in Java example code
		Long longObj = new Long(229999999999L);
		String str = longObj.toString();
		// else
		Long longS = 888888888888L;
		String strLong = longS.toString();

		// compare two long variables
		Long longComp1 = 5555L;
		if (longComp1.equals(55555555L))
			System.out.print("true");

		// compares the two specified long values in Java example

		int i = longS.compareTo(444444L); // -1 first < second
		// 0 first == second
		// 1 first > second
		System.out.print(i);

397LW NO topic_id




AD

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


338

Linkify TextView clickable phone number url adress | linkify-textview-clickable-phone-number-url-adress


android:autoLink="all"

 <!-- text1 automatically linkifies things like URLs and phone numbers. -->
  <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:autoLink="all"
            android:text="@string/link_text_auto"
            />
2

Click Handler | click-handler-android-code


Click Handler Android Java example source code. Open new class as activity and open URL in browser.
In layout.xml file:



In string.xml

myClickHandler



In MainClass.java file

	public void myClickHandler(View view) {
		switch (view.getId()) {
		// open new class as activity
		case R.id.btnOpenClass: {
				Intent pictureActivity = new Intent(getBaseContext(),
						MyClass.class);
				startActivity(pictureActivity);
		}
		break;			
			
		case R.id.btnAbout: {
			//aboutDialogCreate();
		}
			break;
			
		// open url	
		 case R.id.btnHome: {
		 String url = "//android.okhelp.cz/";
		 Intent i = new Intent(Intent.ACTION_VIEW);
		 i.setData(Uri.parse(url));
		 startActivity(i);
		 }break;

		}

	}// end myClickHandler

// listener .. if click on button will scrolling to mTextView bottom
private OnClickListener mButtonListener = new OnClickListener() {
	    public void onClick(View v) {
	      // do something when the button is clicked
	    int nBottom =	mTextView.getBottom();
	    hScrollView.scrollTo(0, nBottom);
	    }
	};

155

Hue saturation, color, colored filtering Bitmap Image Android example | hue-color-colored-filter-bitmap-image-android-example


colored filtering bitmap android

/* Copyright (C) 2011 The Android Open Source Project
//www.apache.org/licenses/LICENSE-2.0
*/
public class MainActivity extends Activity {
private ImageView imageView;
private Button button1;
Drawable bitmapOrg;
private final int[] mColors =
{Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN,
		Color.YELLOW, Color.WHITE};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		imageView = (ImageView)findViewById(R.id.imageView1);
		button1 = (Button)findViewById(R.id.button1);

		
		bitmapOrg = this.getResources().getDrawable(R.drawable.flower_blue);
        
        button1.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                int mColor = (int) Math.floor(Math.random() * mColors.length);
                bitmapOrg.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY);
                imageView.setImageDrawable(bitmapOrg);
                imageView.invalidate();
            }
        });	
 	}

}

73

do while cycle Java basic example | do-while-cycle-java-basic-example


do while Java example

public class MainClass {
	public static void main(String[] arg) {
			String[] arrayOfString = { "Hello", "people", "hello", "world!" };
			int i = 0;
                        // first cycle is always executed
			do {
				System.out.println("Loop: " + i);
				System.out.println(arrayOfString[i]);
				i++;
				
			}while ( i == -1 );
	}
}
/*
Loop: 0
Hello
*/






public class MainClass {
	public static void main(String[] arg) {
			String[] arrayOfString = { "Hello", "people", "hello", "world!" };
			int i = 0;
			do {
				System.out.println("Loop: " + i);
				System.out.println(arrayOfString[i]);
				i++;
				
			}while ( i < arrayOfString.length );
	}
}
/*
Loop: 0
Hello
Loop: 1
people
Loop: 2
hello
Loop: 3
world!
*/

34

How get Android SDK location on PC with Eclipse | how-get-android-sdk-location-on-pc-with-eclipse


How get Android SDK location - PATH on PC from Eclipse tutorial.


  1. Open dialog from menu Window -> AVD and SDK manager

  2. In dialog select Available packages

  3. On top of dialog will displayed similar path: SKD Location: C:\PROGRA~1\Android\android-sdk-windows\





Editace: 2011-09-26 20:49:35
Počet článků v kategorii: 397
Url:long-in-java-example

AD
11 Share
Share
Tweet