HTTP GET
public static void Setdata(String urlStr) {
Log.i("Ten", "Device Edit Done");
HttpUriRequest request = new HttpGet(urlStr); // Or HttpPost(), depends
// on your needs
String credentials = account_password;
String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
request.addHeader("Authorization", "Basic " + base64EncodedCredentials);
httpclient = new DefaultHttpClient();
try {
HttpResponse response = httpclient.execute(request);
HttpEntity httpEntity = response.getEntity();
String state = EntityUtils.toString(httpEntity);
Log.i("Ten", "Ten: " + state);
} catch (ClientProtocolException e) {
Log.i("Ten", "ClientProtocolException:" + e);
e.printStackTrace();
} catch (IOException e) {
Log.i("Ten", "IOException:" + e);
e.printStackTrace();
}
}
HTTP POST
public static String HttpPing(String urlStr) {
String responseBody = "";
try {
String credentials = account_password;
String encoding = Base64.encodeToString(credentials.getBytes(),
Base64.NO_WRAP);
HttpPost httppost = new HttpPost(urlStr);
httppost.setHeader("Authorization", "Basic " + encoding);
List<NameValuePair> postParams;
postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("GetJson", ""));
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
UrlEncodedFormEntity urf = new UrlEncodedFormEntity(postParams,
HTTP.UTF_8);
httppost.setEntity(urf);
response = httpclient.execute(httppost);
int code = response.getStatusLine().getStatusCode();
if (code == 200) {
responseBody = EntityUtils.toString(response.getEntity());
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
//Log.i("Network reponse:",responseBody);
return responseBody;
}
2014年10月20日 星期一
2014年10月7日 星期二
動態修改以動態建立的view視圖 layoutInflater.inflate
解法:
view.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener(){
@Override
public void onGlobalLayout() {
}
});
解釋:
通常是在動態宣告 layoutInflater.inflate後又立刻需要變動 layoutInflater.inflate
(譬如取得剛宣告完的view圖的長寬或上下左右邊界,但系統還沒建立出來)的時候,
會遇到這個問題,
解法是利用getViewTreeObserver這個觀察者(android本身有的內建函式),
去透過Interface的方式在畫面確實被畫出來的時候再返回你所Override的 onGlobalLayout函式去執行你想做的動作。
這個解法蠻漂亮的,所以記錄一下,但我後來發現因為每當畫面更新的時候這個函式就會被觸發,所以還是需要一些參數來控制,詳細就不多贅敘囉!
參考網址:
http://stackoverflow.com/questions/7517636/viewgroup-finish-inflate-event
http://blog.csdn.net/guolin_blog/article/details/12921889
view.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener(){
@Override
public void onGlobalLayout() {
}
});
解釋:
通常是在動態宣告 layoutInflater.inflate後又立刻需要變動 layoutInflater.inflate
(譬如取得剛宣告完的view圖的長寬或上下左右邊界,但系統還沒建立出來)的時候,
會遇到這個問題,
解法是利用getViewTreeObserver這個觀察者(android本身有的內建函式),
去透過Interface的方式在畫面確實被畫出來的時候再返回你所Override的 onGlobalLayout函式去執行你想做的動作。
這個解法蠻漂亮的,所以記錄一下,但我後來發現因為每當畫面更新的時候這個函式就會被觸發,所以還是需要一些參數來控制,詳細就不多贅敘囉!
參考網址:
http://stackoverflow.com/questions/7517636/viewgroup-finish-inflate-event
http://blog.csdn.net/guolin_blog/article/details/12921889
訂閱:
文章 (Atom)