1.使用HttpClient框架发送get.post请求 google收集apache提供的一个发送Http请求框架 public class Tools { public static String getTextFromStream(InputStream is){ byte[] b = new byte[1024]; int len; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { while((len = is…
android在4.0之后已经不允许在主线程执行http请求了. 主线程阻塞,应用会停止刷新界面,停止响应用户任何操作,耗时操作不要写在主线程   只有主线程才能修改UI ANR异常:Application not responding 应用无响应  模拟器与服务器连接: Android模拟器默认的地址是10.0.2.3,默认的DNS也是10.0.2.3,对于在家里上网学习Android的人来讲,一般电脑的IP都是192.168.1.100之类的,不在同一个网段.所以就会出现电脑可以上网但是模拟…
1.get public class Tools { public static String getTextFromStream(InputStream is){ byte[] b = new byte[1024]; int len; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { while((len = is.read(b)) != -1){ bos.write(b, 0, len); } //把字节数组输出流转…
1.简单新闻客户端 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:c…
主线程.子线程.UI的关系 简单的HTTP请求 -------------------------------------------------------- public class MainActivity extends Activity { Handler handler = new Handler(){ //只要消息队列有消息,此方法就会在主线程执行 public void handleMessage(android.os.Message msg) { switch (msg.wha…
使用异步HttpClient框架发送get.post请求 在https://github.com/ 搜索 asyn-http https://github.com/search?utf8=✓&q=asyn-http 下载 loopj/android-async-http public class MainActivity extends Activity { Handler handler = new Handler(){ public void handleMessage(android.os…
第一次写博客,可能格式,排版什么的会非常不美观,不过我主要是为了记录自己的Android学习之路,为了以后能有些东西回顾.既然是为了学习,那我肯定会吸收各位大大们的知道经验,有不足的地方请指出. 通过本次小Demo我学到了: ListView的小小的一个分页功能 加深了对自定义控件的理解 对ListView的优化 对BaseAdapter的使用 自定义Adapter 接口的回调 本次我是通过慕课网(视频链接:http://www.imooc.com/learn/136)学习,要实现下面的效果--…
package com.example.xch.broadcasttest; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInf…
1.在android4中,发起网络http操作,不能在Activity的事件(即主线程)中进行,必须在单独的线程中操作. 另外进行网络操作,需要在manifest文件中增加如下的权限: <uses-permission android:name="android.permission.INTERNET" /> 2.下面给出代码事例 public void loadData() { new AsyncTask<String, Void, String>() { @…
1. 设置mHeaderView.setPadding TOPPADING为负值,隐藏刷新提示头布局 在onTouchEvent事件中进行头布局显示隐藏切换 import java.text.SimpleDateFormat; import java.util.Date; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android…