other type of if statement:
switch (age) {
case = 1:
break;
default:
break;
}
=======================================
int counter = 0 \\easy start from a no.
while (counter <10 ) {
}
========================
Android - if n else, multiple test
int test = 6; \\Main statement
if (){ \\if situation in blacket happen, then do within the brace
}else{ or else do this
}
multiple test with:
( state 1 && state 2) \\ and statement
( state 1 && state 2) \\ or statement
Android -double, systemOUT, scanner(UserInput)
double \\dealing with no. , with dp as well
exp: double tuna;
tuna = 5.28
System.out.println(); \\print the final word, any other thing after that will be next line
System.out.print()
import java.util.Scanner; \\import so you can use the function
Scanner bucky(name it) = new Scanner(System.in) \\ bucky = system.in
double (name variable);
exp: double tuna;
tuna = 5.28
System.out.println(); \\print the final word, any other thing after that will be next line
System.out.print()
import java.util.Scanner; \\import so you can use the function
Scanner bucky(name it) = new Scanner(System.in) \\ bucky = system.in
double (name variable);
Android -Random, case, switch
Random crazy = new Random();
switch(crazy.nextInt(3)){
case 0:
display.setGravity(Gravity.LEFT);
break;
case 1:
display.setGravity(Gravity.CENTER);
break;
case 2:
display.setGravity(Gravity.RIGHT);
break;
default setting is center
switch(crazy.nextInt(3)){
case 0:
display.setGravity(Gravity.LEFT);
break;
case 1:
display.setGravity(Gravity.CENTER);
break;
case 2:
display.setGravity(Gravity.RIGHT);
break;
default setting is center
Android -Thread -
do different things at the same time
framework
Thread timer =new Thread(){
public void run(){
try{
} catch (InterruptedException e){
//debug if it is slow
}finally{
}
}
};
timer.start();
Android -對話框 Dialog; + Toast
Original: http://code.google.com/p/androidbmi/wiki/AndroidDialog
private void openOptionsDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(Bmi.this)
dialog.setTitle(R.string.about_title)
dialog.setMessage(R.string.about_msg)
dialog.setPositiveButton(R.string.ok_label,
new DialogInterface.OnClickListener(){
public void onClick(
DialogInterface dialoginterface, int i){
}
})
dialog.show();
}
}
Add in:
String.xml: about_title, about_msg, ok_label
import: dialoginterface, AlertDialog
p.s. openOptionsDialog => private void
Toast:
別忘了不管是 AlertDialog 或者 Toast,這些函式後都必須加上「show()」方法,這樣提醒訊息才會顯示到螢幕上。
Subscribe to:
Posts (Atom)
