Toast toast=Toast.makeText(mActivity,"test", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER, 0, 0);
toast.show();
2015年6月16日 星期二
2015年5月21日 星期四
Android ScrollView + WebView Layout
<ScrollView
android:id="@+id/my_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<WebView
android:id="@+id/my_web"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp" >
</WebView>
</LinearLayout>
</ScrollView>
android:id="@+id/my_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<WebView
android:id="@+id/my_web"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp" >
</WebView>
</LinearLayout>
</ScrollView>
2015年4月15日 星期三
Android Wear 取消往左滑關閉功能
If the user interaction model of your app interferes with the swipe-to-dismiss gesture, you can disable it for your app. To disable the swipe-to-dismiss gesture in your app, extend the default theme and set the
android:windowSwipeToDismiss attribute to false:<style name="AppTheme" parent="Theme.DeviceDefault"> <item name="android:windowSwipeToDismiss">false</item> </style>
2015年3月24日 星期二
2015年3月19日 星期四
android:ellipsize=“end” ...後面還有文字問題
參考網址: http://stackoverflow.com/questions/17131294/strange-issue-with-androidellipsize-end
text = text.replace('\n',' ');
2015年3月10日 星期二
android post
new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
POST("http://210.243.166.178/apps/Exhibition/api/getSpecificData.php");
}
}).start();
public static String POST(String url){
InputStream inputStream = null;
String result = "";
try {
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
String json = "";
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name","test");
jsonObject.accumulate("number","001");
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
// ** Alternative way to convert Person object to JSON string usin Jackson Lib
// ObjectMapper mapper = new ObjectMapper();
// json = mapper.writeValueAsString(person);
// 5. set json to StringEntity
StringEntity se = new StringEntity(json);
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// 10. convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
Log.d("ddddd", "ddddd result:"+result);
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
// 11. return result
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
@Override
public void run() {
// TODO Auto-generated method stub
POST("http://210.243.166.178/apps/Exhibition/api/getSpecificData.php");
}
}).start();
public static String POST(String url){
InputStream inputStream = null;
String result = "";
try {
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
String json = "";
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name","test");
jsonObject.accumulate("number","001");
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
// ** Alternative way to convert Person object to JSON string usin Jackson Lib
// ObjectMapper mapper = new ObjectMapper();
// json = mapper.writeValueAsString(person);
// 5. set json to StringEntity
StringEntity se = new StringEntity(json);
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// 10. convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
Log.d("ddddd", "ddddd result:"+result);
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
// 11. return result
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
訂閱:
文章 (Atom)