NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits( 2 ); //小數後兩位
System.out.println( "a / b = " nf.format(放要設定的浮點數) );
簡單說就是以NumberFormat類別產生一個實體物件 nf
再用 nf 物件提供的setMaximumFractionDigits方法來設定MaximumFractionDigits屬性為2,也就是小數點後幾位的意思。
最後再用 nf物件提供的format方法來格式化浮點數
如此,輸出的結果就會處理成小數點後兩位了
cookiesp 發表在 痞客邦 留言(0) 人氣()
==============================================================
cookiesp 發表在 痞客邦 留言(4) 人氣()
cookiesp 發表在 痞客邦 留言(0) 人氣()
cookiesp 發表在 痞客邦 留言(0) 人氣()
cookiesp 發表在 痞客邦 留言(0) 人氣()
cookiesp 發表在 痞客邦 留言(0) 人氣()
如果跟我一樣 有時候eclipse都出不明問題的話(我幾乎什麼問題都來一次= =)
1.(進不去 或 ADT裝了卻看不到)
cookiesp 發表在 痞客邦 留言(0) 人氣()
.
//按下
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_VOLUME_UP){
Toast.makeText(mainActivity.this, "按下了上音量鍵", Toast.LENGTH_LONG).show();
return true;
}else if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN){
Toast.makeText(mainActivity.this, "按下了下音量鍵", Toast.LENGTH_LONG).show();
return true;
}else if(keyCode==KeyEvent.KEYCODE_BACK){
Toast.makeText(mainActivity.this, "按下了返回鍵", Toast.LENGTH_LONG).show();
return true;
}else if(keyCode==KeyEvent.KEYCODE_HOME){
Toast.makeText(mainActivity.this, "按下了HOME鍵", Toast.LENGTH_LONG).show();
return true;
}else if(keyCode==KeyEvent.KEYCODE_MENU){
Toast.makeText(mainActivity.this, "按下了Menu鍵", Toast.LENGTH_LONG).show();
return super.onKeyDown(keyCode, event);
}else if(keyCode==KeyEvent.KEYCODE_CAMERA){
Toast.makeText(mainActivity.this, "按下了相機", Toast.LENGTH_LONG).show();
return true;
}else if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){
Toast.makeText(mainActivity.this, "按下了下", Toast.LENGTH_LONG).show();
return true;
}else if(keyCode==KeyEvent.KEYCODE_SEARCH){
Toast.makeText(mainActivity.this, "按下了搜尋", Toast.LENGTH_LONG).show();
return true;
cookiesp 發表在 痞客邦 留言(0) 人氣()
//按下取得手機資訊
button1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
phoneInfo="";
phoneInfo += "DeviceId(IMEI) = " + tel.getDeviceId() + "\n";
phoneInfo += "DeviceSoftwareVersion = " + tel.getDeviceSoftwareVersion()+ "\n";
phoneInfo += "Line1Number = " + tel.getLine1Number() + "\n";
phoneInfo += "NetworkCountryIso = " + tel.getNetworkCountryIso() + "\n";
phoneInfo += "NetworkOperator = " + tel.getNetworkOperator() + "\n";
phoneInfo += "NetworkOperatorName = " + tel.getNetworkOperatorName() + "\n";
phoneInfo += "NetworkType = " + tel.getNetworkType() + "\n";
phoneInfo += "honeType = " + tel.getPhoneType() + "\n";
phoneInfo += "SimCountryIso = " + tel.getSimCountryIso() + "\n";
phoneInfo += "SimOperator = " + tel.getSimOperator() + "\n";
phoneInfo += "SimOperatorName = " + tel.getSimOperatorName() + "\n";
phoneInfo += "SimSerialNumber = " + tel.getSimSerialNumber() + "\n";
phoneInfo += "SimState = " + tel.getSimState() + "\n";
phoneInfo += "SubscriberId(IMSI) = " + tel.getSubscriberId() + "\n";
phoneInfo += "VoiceMailNumber = " + tel.getVoiceMailNumber() + "\n";
new AlertDialog.Builder(mainActivity.this)
.setTitle("手機資訊")
.setMessage(phoneInfo).show();
}
});
AndroidManifest.xml 要加入權限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
cookiesp 發表在 痞客邦 留言(0) 人氣()
隱藏Title Bar (標題列)and Notification Bar(通知列)
可實現螢幕最大化
cookiesp 發表在 痞客邦 留言(0) 人氣()