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.

at java.util.Arrays$ArrayList.get(Arrays.java:75)



Problem in Android application:

E/AndroidRuntime(416): FATAL EXCEPTION: main
E/AndroidRuntime(416): java.lang.IndexOutOfBoundsException
E/AndroidRuntime(416): 	at java.util.Arrays$ArrayList.get(Arrays.java:75)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
E/AndroidRuntime(416): 	at android.widget.Spinner.makeAndAddView(Spinner.java:192)
E/AndroidRuntime(416): 	at android.widget.Spinner.layout(Spinner.java:151)
E/AndroidRuntime(416): 	at android.widget.Spinner.onLayout(Spinner.java:115)


Solution: check code for set and get selection

// Spinner _spin1 contain only  49 items 
// you can set max 48 ( range 0 - 48)
// 50 is IndexOutOfBoundsException
_spin1.setSelection(50);

397LW NO topic_id



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


36

Titlebar title bar change text setTile Android example | titlebar-title-bar-change-text-android-example


Change the title associated with this activity. If this is a top-level activity, the title for its window will change. If it is an embedded activity, the parent can do whatever it wants with it.




 String sTitle = "My new title";
 setTitle(sTitle);



107

Memory usage of application in Android sample code | memory-usage-of-application-in-android-sample-code



public class MainClass extends Activity {
ActivityManager activityManager; 
MemoryInfo memoryInfo; 
final String TAG = "MemInfo";


@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
         memoryInfo = new ActivityManager.MemoryInfo();

        activityManager.getMemoryInfo(memoryInfo);
 
    	           Log.i(TAG, " memoryInfo.availMem " + memoryInfo.availMem);
    	           Log.i(TAG, " memoryInfo.lowMemory " + memoryInfo.lowMemory);
    	           Log.i(TAG, " memoryInfo.threshold " + memoryInfo.threshold);

  Toast.makeText(getApplicationContext(),  String.valueOf( memoryInfo.availMem), Toast.LENGTH_LONG)
		.show();

    } // end onCreate
}
171

WebView change height Android Example | webview-change-height-android-example


The Android WebView changing the height according to text size.
If you need to change the height to a minimum try this source:

//public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) 
WebView _webView; // findById(.....
String entryContent = "";
 _webView.loadDataWithBaseURL(
	"blabol",//  javascript i styly
	entryContent, null,
	"utf-8", null
);

8

Display screen size resolution density dimension Android | display-screen-dimension


Get display, screen resolution - dimension Android phone development example source code.

 Display display = getWindowManager().getDefaultDisplay();
int nWidth = display.getWidth();
int nHeight = display.getHeight();

          DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            //get density per inch for example: 120 , 160 , 240
            mXDpi = metrics.xdpi; // 160 The exact physical pixels per inch of the screen in the X dimension. 
            mYDpi = metrics.ydpi;

// density
int nDensity = metrics.densityDpi; // 160 screen density expressed as dots-per-inch

          float  mMetersToPixelsX = mXDpi / 0.0254f; // 1 inch == 0.0254 metre
          float  mMetersToPixelsY = mYDpi / 0.0254f;
          
// Resolution
// The total number of physical pixels on a screen.
int wPix = metrics.widthPixels; // 320 The absolute width of the display in pixels.
int hPix = metrics.heightPixels; // 480 The absolute height of the display in pixels.
int nWidthDisplay = (wPix < hPix)? wPix : hPix;

float nWidthScreenInInch = wPix / mXDpi; //320 / 160 == 2.0 in inch.
float nHeightScreenInInch = hPix / mYDpi; //480 / 160 == 3.0 in inch.

// for example:
// density 120 per inch
//width 320 pix / 120 dpi == width 2.66 inch
//height 480 pix / 120 dpi == height 4.0 inch 

// density 240 per inch
//width 320 pix / 240 dpi == width 1.33 inch
//height 480 pix / 240 dpi == height 2.0 inch 




Example:
HTC Desire HD
11 (4.3) Diagonal cm (in)
480×800 Resolution
85 (217) ppcm (PPI - Pixels per inch)

480 / 217 = 2.21 inch
800 / 217 = 3.69 inch
Math.sqrt( 2.21*2.21 + 3.69 * 3.69) = 4.3 inch - diagonal

//en.wikipedia.org/wiki/Pixels_per_inch
//en.wikipedia.org/wiki/Dots_per_inch

Typical screen widths:

320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).


Emulator skins in the Android SDK
//developer.android.com/guide/practices/screens_support.html









































Low density (120), ldpi

Medium density (160), mdpi

High density (240), hdpi

Extra high density (320), xhdpi

Small screen
QVGA (240x320) 480x640

Normal screen
WQVGA400 (240x400)

WQVGA432 (240x432)
HVGA (320x480) WVGA800 (480x800)

WVGA854 (480x854)

600x1024
640x960

Large screen
WVGA800** (480x800)

WVGA854** (480x854)
WVGA800* (480x800)

WVGA854* (480x854)

600x1024

Extra Large screen
1024x600 WXGA (1280x800)

1024x768
1280x768
1536x1152
1920x1152

1920x1200
2048x1536
2560x1536

2560x1600
* To emulate this configuration, specify a
custom density of 160 when creating an AVD that uses a WVGA800 or WVGA854 skin.

** To emulate this configuration, specify a custom density of 120 when creating an AVD that
uses a WVGA800 or WVGA854 skin.

† This skin is available with the Android 3.0 platform
364

Android Studio gradle file comment same as java comment | android-studio-gradle-file-comment-same-as-java-comment



// single line
/*
multi line
*/


Editace Jana Žákovská : 2014-02-15 20:32:53
Počet článků v kategorii: 397
Url:at-java-util-arraysarraylist-getarrays-java75
Share
Share
Tweet