Map TreeMap get values to array Java Android example
import java.util.Map;
import java.util.TreeMap;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei"
, "three;drei", "four;vier" };
Map<String, String> map = new TreeMap<String, String>();
for (String s : arrayOfString) {
String[] array = s.split(";");
String sKey = "", sValue = "";
if (array.length > 1) {
sKey = array[0];
sValue = array[1];
map.put(sKey, sValue);
}
}
Object[] objectArrayOfValues = map.values().toArray();
for (int i = 0; i < objectArrayOfValues.length; i++) {
System.out.println(objectArrayOfValues[i]);
}
}// end main
}
/*
vier
eine
drei
zwei
zwei
*/
396LW NO topic_id
AD
Další témata ....(Topics)
Date getDate is deprecated Java Android example code:
long dayInMili = 100000000;
GregorianCalendar calToDay = new GregorianCalendar();
int nD = calToDay.get((Calendar.MILLISECOND)); // +dayInMili;
System.out.println(nD);
long lTime = calToDay.getTimeInMillis();
System.out.println(lTime);
Date dtA = new Date(lTime); // today
///@SuppressWarnings("deprecation")
int nD1 = dtA.getDate(); // DEPRECATED Day Of Month 1 - 31
System.out.println(nD1+" nD1");
GregorianCalendar cal = new GregorianCalendar();
int nD2 = calToDay.get(Calendar.DATE); // Day Of Month
System.out.println(nD2+" nD2");
cal.setTimeInMillis(lTime+dayInMili);// setTime(dtA);
int nD3 = cal.get(Calendar.DATE); // Day Of Month + 1 day
System.out.println(nD3+" nD3");
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.
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);
Try this:
- check names of drawables (file name must contain only abc...xyz 012...789 _ . in Resources folder ,
names have to start with lower case
MyImage.jpg == problem ,
names with space
my image.jpg == problem,
names with -
my-image.png == problem)
- check duplicate names with other extension ( my_image.jpg - my_image.png makes the problem)
- restart Android Studio
- if problem persist:
- check c:\Users\me\AndroidStudioProjects\myProject\myModule\build\intermediates\res\merged\debug\ drawable folder for corupted names or delete ALL drawable folders
- synk projekt, rebuild projekt
- if problem persist:
- restart Android Studio, wait for complete closure of the Android Studio!
- check names of drawables (file name must contain only abc...xyz 012...789 _ . in Resources folder ,
names have to start with lower case
MyImage.jpg == problem ,
names with space
my image.jpg == problem,
names with -
my-image.png == problem)
- check duplicate names with other extension ( my_image.jpg - my_image.png makes the problem)
- restart Android Studio
- if problem persist:
- check c:\Users\me\AndroidStudioProjects\myProject\myModule\build\intermediates\res\merged\debug\ drawable folder for corupted names or delete ALL drawable folders
- synk projekt, rebuild projekt
- if problem persist:
- restart Android Studio, wait for complete closure of the Android Studio!
Download image file from URL to ImageView Java Android source example code.
Context context = thisClass.this;
Drawable image = ImageOperations(context,
"//www.okhelp.cz/images/android/ad_4.png"
,"image.jpg");
ImageView imgView;
imgView = (ImageView)findViewById(R.id.idImageView);
imgView.setImageDrawable(image);
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)
Get bitmap size without allocation of memory:
Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)
Get bitmap size without allocation of memory:
BitmapFactory.Options options = new BitmapFactory.Options();
// If set to true, the decoder will return null (no bitmap), but the out... fields will still
// be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
int imageHeight = options.outHeight; // 1024
int imageWidth = options.outWidth; // 860
String imageType = options.outMimeType; // .jpg .png .gif
Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
float density = getResources().getDisplayMetrics().density;
Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memoryInfo);
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
String memMessage = String.format(
"Free=%d kB,
MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB",
freeMemory,
maxMemory,
memoryInfo.getTotalPss() / 1024.0,
memoryInfo.getTotalPrivateDirty() / 1024.0,
memoryInfo.getTotalSharedDirty() / 1024.0);
((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );
Editace: 2013-12-09 13:29:16
Počet článků v kategorii: 396
Url:map-treemap-get-values-to-array-java-android-example