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.

String Array of Array Java Example



Set, get string , array of array of strings, Java example code

	public final static String[][]_arArOfString_1 = {
		new String[] {"bla","bla","hello world!"},
		new String[] {},
		new String[] {},
		new String[] {},
		new String[] {},
		new String[] {}
	};
String sOut = _arArOfString_1[0][2]; // hello world!

397LW NO topic_id



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


359

Saving Activity state int String Array Double on Android | saving-activity-state-int-string-array-double-on-android



private int[] mData = new int[2]; // fill some values into array!!
 @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean("myBoolean", true);
        outState.putDouble("myDouble", 2.7);
        outState.putInt("myInt", 5);
        outState.putString("myString", "Heloo girls!");
       int[] data = new int[mData.length];
        for (int i = 0; i < data.length; i++) {
            data[i] = mData[i];
        }
        outState.putIntArray("myArray", data);

    }
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  boolean myBoolean = savedInstanceState.getBoolean("myBoolean", false); // false basic value
  double myDouble = savedInstanceState.getDouble("myDouble", 1.5); // 1.5 basic value
  int myInt = savedInstanceState.getInt("myInt", 10);
  String myString = savedInstanceState.getString("myString", "Hello boys!");
  int[] data = savedInstanceState.getIntArray("myArray");
  
  if (data != null && data.length == mData.length) {
            for (int i = 0; i < data.length; i++) {
                mData[i] = data[i];
            }
        }
}
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  boolean myBoolean =  savedInstanceState != null ? savedInstanceState.getBoolean("myBoolean", false) : true;
// etc.  .......
}

300

SurfaceView implements Runnable Android Code | surfaceview-implements-runnable-android-code



package cz.okhelp.surfview;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

public class MainActivity extends Activity implements OnTouchListener {
	OurView v;
	Bitmap ball, blob;
	float x, y;
	Sprite sprite;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_our_view);
		v = new OurView(this);
		v.setOnTouchListener(this);
		ball = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
		x = y = 0;
		setContentView(v);
	}


	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		v.pause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		v.resume();
	}

	public class OurView extends SurfaceView implements Runnable {
		Thread t = null;
		SurfaceHolder holder;
		boolean isItOK = false;

		public OurView(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
			holder = getHolder();
		}

		public void run() {
			// TODO Auto-generated method stub
			while (isItOK == true) {
				// perform canvas drawing
				if (!holder.getSurface().isValid()) {
					continue;
				}
				// sprite = new Sprite(OurView.this,blob);
				Canvas c = holder.lockCanvas();
				c.drawARGB(255, 100, 100, 10);
				c.drawBitmap(ball, x, y, null);
				// onDraw(c);
				holder.unlockCanvasAndPost(c);
			}
		}

		protected void onDraw(Canvas canvas) {
			// sprite.onDraw(canvas);
		}

		public void pause() {
			isItOK = false;
			while (true) {
				try {
					t.join();
				} catch (InterruptedException e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				break;
			}// end while
		}

		public void resume() {
			isItOK = true;
			t = new Thread(this);
			t.start();
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			x = event.getX();
			y = event.getY();

			break;
		case MotionEvent.ACTION_UP:
			x = event.getX();
			y = event.getY();

			break;
		case MotionEvent.ACTION_MOVE:
			x = event.getX();
			y = event.getY();

			break;
		}// end switch

		return true;
	}

}

134

Draw Oval Android basic example | draw-oval-android-basic-example


drawOval(), setStrokeWidth(), setStyle()


public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {

			canvas.drawColor(Color.CYAN);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStyle(Paint.Style.STROKE); 
			p.setStrokeWidth(4.5f);
			// opacity
			//p.setAlpha(0x80); //
 
			canvas.drawOval(new RectF(50, 50, 20, 40), p);;
		}

	}
}
334

Lenovo A6000 smartphone pictures from camera 8mpx review | lenovo-a6000-smartphone-pictures-from-camera-8mpx


Pictures taken by front camera Lenovo A6000 smartpohone - review.
Do not take pictures against the sun.
Stay in the shade. Keep lens clean.

Night without flash

Lenovo A6000 pictures quality
Lenovo A6000 pictures quality
Lenovo A6000 pictures quality
Lenovo A6000 pictures quality




Misty - smog


Without flash in room - TV screen


lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
215

Round number float - double to int - long Java example | round-number-float-to-int-java-example



int nf = Math.round(5.789f);
System.out.print(nf); // 6

float f = 28.611f; 
int n3 = Math.round(f);
System.out.println(n3); // 29

double d = 1234.56;
long lon = Math.round(d);
System.out.println(lon); // 1235

int diff = 90 - 40;
// float fDeleni = diff / 10; // error code
float fDeleni = (float)diff / 10.f; // ok
int nRound = Math.round(fDeleni);


// Caution:
int n2 = (int) 8.999f;
System.out.println(n2); // 8




Editace Jana Žákovská : 2013-12-09 11:04:09
Počet článků v kategorii: 397
Url:string-array-of-array-java-example
Share
Share
Tweet