Time of Update: 2018-12-06
Android原有的屬性可能不能滿足我們現在要做的事,畢竟有些人就是會天馬行空的想出一些Android不會做的東西。今天就簡單的寫下怎樣為自訂控制項自訂屬性,看這種描述有點暈,轉過來就是控制項和屬性都是自訂的吧。哈~上面是運行介面,有兩個自訂的Button,主要是用來區分。首先在res/values/目錄下建立attrs.xml檔案,用來自訂屬性<?xml version="1.0" encoding="utf-8"?><resources>
Time of Update: 2018-12-06
PendingIntent: //建立PendingIntent的方法: getActivity(Context context,int requestCode,Intent intent,int flags) //啟動一個Activity getBroadcast(Context context,int requestCode,Intent intent,int flags) //發送一個廣播 getService(Context
Time of Update: 2018-12-06
User Location主要用於擷取使用者的位置和追蹤使用者的移動 關鍵API: Location Manager用於管理Android的使用者定位服務;Location Provider提供多種定位方式供開發人員使用 定位方式的分類: 1. 使用GPS衛星進行定位,需要在AndroidManifest當中聲名許可權android.permission.ACCESS_FINE_LOCATION 2.
Time of Update: 2018-12-06
使用SAX事件驅動模型解析xml資料: sax的工作原理簡單地說就是對文檔進行順序掃描,當掃描到文檔(document)開始與結束、元素(element)開始與結束、文檔(document)結束等地方時通知事件處理函數,由事件處理函數做相應動作,然後繼續同樣的掃描,直至文檔結束。以下是建立SAX解析的步驟: 1. 建立SAXParserFactory對象 SAXParserFactory factory = SAXParserFactory.newInstance(); 2.
Time of Update: 2018-12-06
我好像總是對控制項情有獨鐘的O(∩_∩)O,近來就打算寫寫Android基礎控制項的使用,希望可以從中挖掘一些新的東西。這次的例子是從EditText中輸入文字,然後在TextView中同步顯示,實現即時輸入輸出。關鍵就是用OnKeyListener監聽EditText的鍵盤輸入事件。例子比較簡單,直接上代碼。main.xml布局:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://
Time of Update: 2018-12-06
擷取最佳的LocationProvider,這個最佳是根據條件相對而言滴 //現在先來取得電子裝置中都提供了哪些LocationProvider List<String> providers = locationManager.getAllProvider(); for(Iterator iterator = providers.iterator ; iterator.hasNext()){ String s = (String)iterator.
Time of Update: 2018-12-06
ContentValues values = new ContentValues();//首先向RawContacts.CONTENT_URI執行一個空值插入,目的是擷取系統返回的rawContactId Uri rawContactUri = context.getContentResolver().insert(RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri);
Time of Update: 2018-12-06
先呈上我測試動畫的介面:布局檔案main.xml為:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"
Time of Update: 2018-12-06
***這個例子只能是針對於Json對象而不是Json數組,Json數組需要轉為為Json對象,這是下一節的事情。 1. 先有一個JSON對象String str = "{\"name\":\"Michael\",\"age\":20}",JSON類可以直接把JSON資料轉化為java對象 2. 建立User類 public class User{ private String name; private int age; public
Time of Update: 2018-12-06
效果:有兩個Activity分別為A和B,從A中採用Bundle封裝資料向B中傳遞資料,然後使用startActivityForResult在B中修改後回傳資料。第一個Activity的layout如main.xml: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3
Time of Update: 2018-12-06
Google的Geocoding服務功能: 1. 查詢某地址的經緯度 2. 查詢某經緯度的具體地址 Android的Geocoding替代品 //根據地址查詢經緯度的網址及其解釋 http://maps.googleapis.com/maps/api/geocode/json?address=SFO&sensor=false
Time of Update: 2018-12-06
1. 接受來自App Widget的廣播 //Androidmanifest中的檔案旨要,只要有個一action符合就會調用繼承AppWidgetProvider的類: <receiver android:name="繼承AppWidgetProvider的類"> <intent-filter> <action
Time of Update: 2018-12-06
public void startActivity(Intent intent, int animationEnterId, int animationLeaveId) { Activity activity = this; activity = TinyUtils.getRootActivity(this); if (activity == this) { super.startActivity(intent); } else {
Time of Update: 2018-12-06
www.json.org這是JSON的官方網站。 首先,我,我們需要在code.google.com/p/google-gson/downloads/list下載JSON的jar包,解析後把gson-1.6.jar檔案匯入到你那個需要解析的項目中去。 解析JSON例子,如下: 1、
Time of Update: 2018-12-06
1. 這是Json資料,String str = "[{\"name\":\"Michael\",\"age\":20},{\"name\":\"Mike\",\"age\":21}]"。這個Json資料有一個數組,數組裡面有兩個Json對象 2. 首先必鬚生成Type對象,使用以下的方式(User是上一節的User類): Type listType = new TypeToken<LinkedList<User>>(){}.getType();
Time of Update: 2018-12-06
/** * 不規則"圖形按鈕控制項" * */public class TrapezoidImageButton extends ImageButton { public TrapezoidImageButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public TrapezoidImageButton(Context
Time of Update: 2018-12-06
系統打電話介面:Intent intent = new Intent();//系統預設的action,用來開啟預設的電話介面intent.setAction(Intent.ACTION_CALL);//需要撥打的號碼intent.setData(Uri.parse("tel:"+i)); callPhoneAndSendMessage.this.startActivity(intent); 系統發簡訊介面:Intent intent = new
Time of Update: 2018-12-06
1.AppWidgetProviderInfo對象: 為App
Time of Update: 2018-12-06
//產生一個請求對象 HttpGet httpGet = new HttpGet("http://www.baidu.com"); //產生一個http用戶端對象 HttpClient httpClient = new DefaultHttpClient(); //用戶端向伺服器發送請求,返回一個響應對象 HttpResponse
Time of Update: 2018-12-06
使用Get方法提交: 其他步驟與上一節的操作相符,只是在傳送地址的時候發送參數的格式如下: //Sname和Sage是實際的資料 name和age則是例如是輸入框中的名字 url = "伺服器的地址"+ "?" + "name=" + Sname + "&age=" +