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
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]);
}
396LW NO topic_id
AD
Další témata ....(Topics)
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
- 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
BufferedWriter, FileWriter, write, close MODE_APPEND Java and Android example
Write to file Android example
Write to file Java example
Write to file Android example
try {
String MYFILE = "my_file";
String strText = "My text";
// MODE_APPEND, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE
// create new file or rewrite existing
FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_PRIVATE);
// append to file
FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_APPEND);
fos.write(strText.getBytes());
fos.close();
} catch (IOException e) {
e.toString();
}
Write to file Java example
try {
// new file
BufferedWriter out = new BufferedWriter(
new FileWriter("outfilename"));
// append text
BufferedWriter out = new BufferedWriter(new FileWriter("outfilename", true));
out.write("some text");
out.close();
} catch (IOException e) {
e.toString();
}
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"
/>
Use this code for example in some method or function
// public Object getSystemService (String name)
// Return the handle to a system-level service by name.
// The class of the returned object varies by the requested name.
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//public boolean hideSoftInputFromWindow (IBinder windowToken, int flags)
//EditText myEdit = (EditText)findViewById(R.id.idEditText);
inputMethodManager .hideSoftInputFromWindow(myEdit.getWindowToken(), 0);
onSaveInstanceState, onRestoreInstanceState , save preferences
int mCurrentPhotoIndex = 0;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("photo_index", mCurrentPhotoIndex);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
super.onRestoreInstanceState(savedInstanceState);
}
// or save preferences for new start of Activity in onStop
//onCreate or onResume or onStart etc.
public void loadPreferences() {
SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
mCurrentPhotoIndex = settings.getInt("mCurrentPhotoIndex",mCurrentPhotoIndex);
// String_sOtazka = settings.getString("_sOtazka", _sOtazka);
}
// onStop
public void savePreferences() {
SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("mCurrentPhotoIndex", mCurrentPhotoIndex);
// String, boolean, float ...
// editor.putString("mButton1", mButton1.getText().toString());
editor.commit();
}
Editace: 2011-09-26 20:51:00
Počet článků v kategorii: 396
Url:int-java-android-example