這是每個我接觸到的ImageView我的應用程序等待大約5秒的時間我的代碼 然後chrashes應用程序崩潰每次我做一個HTTP請求時
我有INTERNET權限
在服務器端我有一個PHP頁面讀取GET和數據庫中的
public class Home extends Activity {
ImageView lightbut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ImageView lightbut = (ImageView) findViewById(R.id.light);
lightbut.setClickable(true);
lightbut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("== My activity ===","OnClick is called");
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpGet httpPost = new HttpGet("http://192.168.0.102/HR/index.php?command=ligthsoff");
try {
HttpResponse response = httpClient.execute(httpPost);
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
}
});
}
爲了便於使用,請查看[droidQuery](http://bit.ly/droidquery)。獲取'XML'或'JSON'就像'$ .getJSON(url)'或'$ .getXML(url)'一樣簡單。 – Phil
這些天你應該使用Android的排球庫https://developer.android.com/training/volley/index.html – Benitok