Está en la página 1de 7

INSTRUCCIONES ANDROID JAVA ECLIPSE

onCreateAndPrepareToDisplay()
onPrepareToDisplay()
onVisible()
onBeginInteraction()
onPauseInteraction()
onInvisible()
onDestroy()

[instead of
[instead of
[instead of
[instead of
[instead of
[instead of
[no change]

onCreate() ]
onRestart() ]
onStart() ]
onResume() ]
onPause() ]
onStop]

---------------------------------------------------------------------onActivityResult
------------------------------------------------------------------------------Operator Precedence
Operators

Precedence

postfix
unary
multiplicative
additive
shift
relational
equality
bitwise AND
bitwise exclusive OR
bitwise inclusive OR
logical AND
logical OR
ternary
assignment

expr++ expr-++expr --expr +expr -expr ~ !


* / %
+ << >> >>>
< > <= >= instanceof
== !=
&
^
|
&&
||
? :
= += -= *= /= %= &= ^= |= <<= >>= >>>=

-----------------------------------------------------------------------------resize a bitmap
android.graphics.Bitmap.createScaledBitmap
or
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);

// recreate the new Bitmap


Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, fals
e);
return resizedBitmap;
}
-------------------------------------------------------------cortar un trozo de imagen de otra mas grande
// Crop bitmap
Bitmap newBitmap = Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX
, HEIGHT_PX, null, false);

-------------------------------------------------------------PASAR ARRAY <-> LIST


public static void main(String[] args) {
String[] arrayItems = new String[3];
arrayItems[0] = "Oleg";
arrayItems[1] = "Mazurashu";
arrayItems[2] = "FaYnaSoft Labs";
//ARRAY -->LIST
List<String> list = Arrays.asList(arrayItems);
System.out.println("list item 5: " + list.get(2));
//LIST -->ARRAY
String[] newArray = new String[list.size()];
list.toArray(newArray);
System.out.println("array item 5: " + newArray[2]);
}
-----------------------------------------------------------cambiar nombre a ficheros
A esta nueva actividad le daremos el nombre de ActividadInfo,
si le damos otro nombre tambin debemos editar la variable ACT_INFO
que se encuentra en ActividadCompleja.java para darle el nombre
correspondiente de la clase.
--------------------------------------------------------------PASAR DATOS DE UN MAIN A OTRO (PASAMOS CONTENIDO EDITTEXT)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 = (EditText) findViewById(R.id.et1);}
public void ejecutar(View view) {
Intent i = new Intent(this, Actividad2.class);
i.putExtra("direccion", et1.getText().toString());

startActivity(i);}
//PASAMOS VARIABLE DIRECCION
Noticia objeto = (Noticia)getIntent().getExtras().getSerializable("("direccion")
;
--------------------------------------------------------------CAMBIAR CONTENIDO CUADRO TEXTO
et1=(EditText)findViewById(R.id.editText1);
et2=(EditText)findViewById(R.id.editText2);
tv3=(TextView)findViewById(R.id.textView3);
String valor1=et1.getText().toString();// et1 y et2 son editText
String valor2=et2.getText().toString();
int nro1=Integer.parseInt(valor1);//pasamos string a integer
int nro2=Integer.parseInt(valor2);
int suma=nro1+nro2;
String resultado=String.valueOf(suma);//pasamos integer a string
tv3.setText(resultado);
-----------------------------------------------------------MOSTRAR MENSAJE
//Mostramos un Toast
Toast.makeText(getApplicationContext(), "Mi primer Toast", Toast.LENGTH_LONG).sh
ow();
------------------------------------------------------Changing ImageView source:
Using setBackgroundResource() method:
myImgView.setBackgroundResource(R.drawable.monkey);
you are putting that monkey in the background.
I suggest the use of setImageResource() method:
myImgView.setImageResource(R.drawable.monkey);
or with setImageDrawable() method:
myImgView.setImageDrawable(getResources().getDrawable(R.drawable.monkey));
setImageDrawable(android.graphics.drawable.Drawable)
or
setImageBitmap(android.graphics.Bitmap)
----------------------------------------------------------fill_parent (en desuso y renombrado MATCH_PARENT en el Nivel API 8 y superior)
Configuracin de la presentacin de un widget a fill_parent obligar a que se expanda
para ocupar todo
el espacio que est disponible en el elemento de diseo que ha sido colocado. Es ms
o menos equivalente
a establecer el dockstyle de un formulario de control de Windows para llenar.

Configuracin de un diseo de nivel superior o control a fill_parent obligar a ocupar


toda la pantalla.
wrap_content
Configuracin de un Ampliar a wrap_content obligar a ampliar slo lo suficientemente
lejos para contener los valores
(o controles secundarios) que contiene. Para los controles - como cuadros de tex
to (TextView) o imgenes (ImageView)
- esto envolver el texto o imagen que se muestran. Para los elementos de diseo q
ue se cambie el tamao del diseo para
adaptarse a los controles / layouts aadido como sus hijos.
Es ms o menos el equivalente a establecer la propiedad Tamao automtico de un formul
ario de control de Windows True.
----------------------------------------------------------ABRIR UNA SEGUNDA ACTIVIDAD
EN EL FICHERO

ReminderEditActiviy.class"

package es.greval.taskReminder;
import android.app.Activity;
import android.os.Bundle;
public class ReminderEditActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_edit);
}
}
EN EL FICHERO AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas....
...
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ReminderEditActivity"></activity>
</application>
</manifest>
CREAMOS EL FICHERO DE LA SEGUNDA PANTALLA:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView

reminder_edit.xml

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="@string/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
...
</LinearLayout>
</ScrollView>
----------------------------------------------------------Java tiene en total 8 tipos de datos.
Enteros
short - 16 bits.
int 32 bits.
long - 64 bits.
Nmeros Reales
float - 32 bits.
double - 64 bits.
Otros
boolean - 1 bit (true false, nicos valores posibles).
char - 16 bits.
String - *Cadena de caracteres*.
---------------------------------------------------------Pasar de int a String (2 maneras)
Nos hacemos del mtodo valueOf de la clase String o del toString de la clase Integ
er.
int numero = 1234;
String cadena = "";

cadena = String.valueOf(numero);
cadena= Integer.toString(numero);

Pasar de String a int


Utilizamos el mtodo parseInt de la clase Integer.
String cadena = "1234";
int numero = 0;
numero = Integer.parseInt(cadena)
Asimismo, la clase Float tambin posee un mtodo parseFloat
de igual caractersticas.
-----------------------------------------------------------------cmo definir un array:
//Para un array unidimensional (un vector)
Tipo_de_dato Nombre_Array[];
Nombre_Array = new Tipo_de_dato[tamao];
//o bien, para un array bidimensional (una matriz)
Tipo_de_dato Nombre_Array[][];
Nombre_Array = new Tipo_de_dato[tamaoX][tamaoY];
// Tambin podemos usar para una dimensin...
Tipo_de_dato Nombre_Array[] = new Tipo_de_dato[tamao];
//o para dos dimensiones...
Tipo_de_dato Nombre_Array[][] = new Tipo_de_dato[tamaoX][tamaoY];
-----------------------------------------------------------------IF
if (x >= 10) {
System.out.println("x es mayor o igual a 10!");
} else {
System.out.println("x es menor a 10");
}
SWITCH
int x = 5;
switch(x) {
case 1:
System.out.println("x vale 1");
break;
case 2:
System.out.println("x vale 2");
break;
case 5:
System.out.println("x vale 5");
break;

default:
System.out.println("x no es equivalente a ninguna de las anteriores...")
;
break;
}
FOR
for (i = 0; i < 10; i++) {
System.out.println("Este bucle se ha repetido " + i + " veces...");
}
while (i!=10){ ++1}

También podría gustarte