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

Android很有用的代码片段

 2010-09-21 02:12:00 来源:WEB开发网   
核心提示:public class Setting extends PreferenceActivity{public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);addPreferencesFromResource(R

public class Setting extends PreferenceActivity

{

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”/>

回目录13:通过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();

}

}

回目录14:显示toast

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

上一页  1 2 3 

Tags:Android 有用 代码

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