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.

Create Button and TextView dynamically - Android sample


public class MainActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
            TextView textView = new TextView(this);
            textView.setText("Text View ");
            LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
            layout.addView(textView, p);

            Button buttonView = new Button(this);
            layout.addView(buttonView, p);
    private OnClickListener mThisButtonListener = new OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "Hello !",

397LW NO topic_id


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


LayoutLib is too recent. Update your tool Eclipse Android | layoutlib-is-too-recent-update-your-tool-eclipse-android

LayoutLib is too recent. Update your tool!
Eclipse Android Graphical layout resolving problem.

  1. Open in Eclipse menu Help ->Check for Updates

  2. Select updates: [caption id="attachment_593" width="300" caption="Android Eclipse updates dialog"]android-eclipse-updates[/caption]

  3. Press Next and update all

  4. Restart Eclipse

  5. [caption id="attachment_596" align="alignleft" width="300" caption="Restart Eclipse if updates finished."]layoutlib-is-too-recent-update-your-tool[/caption]


Samsung Galaxy Mini (S5570) | samsung-galaxy-mini-s5570

Brand Samsung
Model (codename) Galaxy Mini (S5570)
Price (cena, včetně DPH) 3500 / 06.2012
Display size in Inch (v palcích) 3.14
Display-resolution 240x320
Dotek-typ kapacitní
CPU typ MSM7227
CPU MHz 600
CPU core
L2 cache yes
RAM 256
ROM 512
GPU Adreno 200
NenaMark2 Benchmark
Baterie mAh 1200
Foto MPx 3
Autofocus no
Video QVGA (320 x 240) při 15 frames/s
Official Android ICS Android Froyo 2.2
CyanogenMod support yes
Dotek-prstů-max Dual-touch (two fingers)
Display-ppi 127
Display-retina 39%
Networks GSM&EDGE (850 / 900 / 1.800 / 1.900 MHz) 3G (900 / 2.100 MHz)
Connectivity Bluetooth V2.1 , USB V2.0 , USB mass storage , SyncML(DM) , WIFI , AGPS, 3.5 mm jack

Samsung S5570 Galaxy Mini - image

Delete Bitmap Android Example | delete-bitmap-android-example

If some memory leak - problem try release of memory used of a big Bitmap what already not to need;
Bitmpap bmp; // not null
bmp = null;

final boolean bmpIsRecycled = bmp.isRecycled()
// Returns true if this bitmap has been recycled.

Free the native object associated with this bitmap, and clear the reference to the pixel data. This will not free the pixel data synchronously; it simply allows it to be garbage collected if there are no other references. The bitmap is marked as "dead”, meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing. This operation cannot be reversed, so it should only be called if you are sure there are no further uses for the bitmap. This is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this bitmap.

Get Resource ID by Resources String Name Android example | get-resource-id-by-resources-string-name-android-example

// image from res/drawable
	int resID = getResources().getIdentifier("my_image", 
			"drawable", getPackageName());
// view
	int resID = getResources().getIdentifier("my_resource", 
			"id", getPackageName());

// string
	int resID = getResources().getIdentifier("my_string", 
			"string", getPackageName());


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: 2011-10-22 07:54:35
Počet článků v kategorii: 397

11 Share