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.

Hashtable find value by key Java Android example


Hashtable find value by key Java Android basic example.

import java.util.Hashtable;

public class MainClass {
	public static void main(String[] arg) {
		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };

	    Hashtable hashTable = new Hashtable();
	    for(String s: arrayOfString){
	    	String[] array = s.split(";");
	    	String sKey ="", sValue="";
	    	if(array.length > 1){
	    	sKey = array[0]; sValue = array[1];
	    		hashTable.put(sKey, sValue);

       // check if key exists 	    
	   if( hashTable.containsKey("two")){
		System.out.print("two = " + hashTable.get("two"));
two = zwei

397LW NO topic_id


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


Unable to execute dex: Multiple dex files define Eclipse Android | unable-to-execute-dex-multiple-dex-files-define-eclipse-android

Try each step separately:

  1. Restart Eclipse

  2. Clean project and rebuild

  3. Create a new project and try it if the problem persists, if no move copy project to other folder, delete project from workspace , create new project same name and copy java, xml etc. files to new project

  4. Close Eclipse, backup folder c:\Users\myName\workspace\.metadata and delete it. Restart Eclipse try again import project to workspace

  5. Re-installing the Android Developer Tools

  6. Re-installing Eclipse - rename old folder with Android to Android_old, create new folder C:\Program Files\Android and copy new Eclipse with sdk into new folder

  7. Created a new project importing from the file system

  8. Created a new project from subversion


How to make a horizontal line in Android application example code | how-to-make-a-horizontal-line-in-android-application-example-code

In html is horizontal line a tag br. In Android source code you can use a View as xml example bellow.


layout-sw600dp values-sw600dp Android example of use | layout-sw600dp-values-sw600dp-android-example-of-use

Why the app selects data from basic layout folder if smallest width is higher then the number in folder name?
Example 1
layout-sw600dp values-sw600dp (smallest width sw for data usage from this folder is 600dp density independent pixel!!!!!)
Device screen resolution is 1200 x 900 px (pixel) Wow, app to be select data from sw600dp folder! Realy?
DPI of device screen - dot per inch (pixel per inch) is 480 pixel it is wery important number!

  1. App selects smallest dimension of screen. In our case 900 px
    Medium screen have 160 dpi (The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen.).

  2. App calculate ratio 480 / 160 = 3 (The conversion of dp units to screen pixels: px = dp * (dpi / 160))

  3. App calculate smallest dimesnion of screen in dp 900 / 3 = 300 dip or dp (density independed pixel).

  4. App selects data from basic values and layout folder because sw600dp is greater than 300dp.

In our case smallest dimension of screen must be at least 1800 real - physical pixels (1800 px / 3 ratio(dpi/160) = 600 dp (dip density independend pixels) to be used data from folders values-sw600dp and layout-sw600dp.

Example 2 see Example 1 abouve
Device: Nexus 7 (2012) selected from Android Studio tool layout editor
Resolution: 800x1280 px
DPI: tvdpi (approximately 213dpi)
Ratio: 1.33 (213 / 160)
Smallest width in px: 800
Convert px to dp: 601.5 (800 / 1.33)
Result:Smallest width is 601.5dp The App to be used data from folders values-sw600dp and layout-sw600dp.

drawBitmap createBitmap by array of colours Android example | drawbitmap-createbitmap-draw-bitmap-by-array-of-colours-android-example

public static Bitmap createBitmap (int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)

//  //www.apache.org/licenses/LICENSE-2.0
public class MainActivity extends Activity {
	    private static final int WIDTH = 50;
	    private static final int HEIGHT = 50;
	    private static final int STRIDE = 64;   // must be >= WIDTH
	    private static int[] createColors() {
	        int[] colors = new int[STRIDE * HEIGHT];
	        for (int y = 0; y < HEIGHT; y++) {
	            for (int x = 0; x < WIDTH; x++) {
	                int r = x * 255 / (WIDTH - 1);
	                int g = y * 255 / (HEIGHT - 1);
	                int b = 255 - Math.min(r, g);
	                int a = Math.max(r, g);
	                colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;
	        return colors;
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(new SampleView(this));

	private static class SampleView extends View {

		public SampleView(Context context) {

		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();

            int[] mColors = createColors();
            int[] colors = mColors;

            Bitmap bitmap = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
			canvas.drawBitmap(bitmap, 50,20, paint); 



Not request focus EditText if startup Android | not-request-focus-edittext-if-startup-android

Not request focus EditText if startup Android - hide keyboard if startup.

Remove: from EditText

Create a LinearLayout and set the:
attributes android:focusable="true" android:focusableInTouchMode="true"

        android:orientation="vertical" >

Editace: 2013-12-09 10:56:31
Počet článků v kategorii: 397

11 Share