WEB开发网
开发学院手机开发Android 开发 Android很有用的代码片段集锦 阅读

Android很有用的代码片段集锦

 2010-06-13 15:23:00 来源:WEB开发网   
核心提示:{public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);addPreferencesFromResource(R.xml.settings);}}Setting.xml:android:key=”setin

{

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.settings);

}

Setting.xml:

android:key=”seting2″

android:title=”@string/seting2″

android:summary=”@string/seting2″/>

android:key=”seting1″

android:title=”@string/seting1″

android:summaryOff=”@string/seting1summaryOff”

android:summaryOn=”@stringseting1summaryOff”/>

14:通过HttpClient从指定server获取数据

DefaultHttpClient httpClient = new DefaultHttpClient();

HttpGet method = new HttpGet(“http://www.baidu.com/1.html”);

HttpResponse resp;

Reader reader = null;

try {

// AllClientPNames.TIMEOUT

HttpParams params = new BasicHttpParams();

params.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 10000);

httpClient.setParams(params);

resp = httpClient.execute(method);

int status = resp.getStatusLine().getStatusCode();

if (status != HttpStatus.SC_OK) return false;

// HttpStatus.SC_OK;

return true;

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

if (reader != null) try {

reader.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

15:显示toast

Toast.makeText(this._getApplicationContext(), R.string._item, Toast.LENGTH_SHORT).show();

上一页  1 2 3 

Tags:Android 有用 代码

编辑录入:coldstar [复制链接] [打 印]
赞助商链接