服务器端数据没有问题,但是请求不到数据! |
|
发送请求那行代码过不去
|
|
40分 |
访问网络操作放在主线程了,放到分线程即可!
|
getData方法在分线程即可!
|
|
public List<Map<String, Object>> getData(){
final List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); new Thread(){ public void run(){ try { String url=”http://guoqiang.x9.fjjsp01.com/factory/Get/null”; // String url=”http://vsdemo.x9.fjjsp01.com/quality/mobile/getCustomer”; HttpGet post=new HttpGet(url); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(post); // 执行get请求. // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); // response = httpClient.execute(post);//发送请求 Toast.makeText(getApplicationContext(), “2”, 0).show(); |
|
貌似这样写也不对啊!
|
|
有错误吗? |
|
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.import_company_code_activity); listView=(ListView)findViewById(R.id.list); List<Map<String, Object>> list=getData(); listView.setAdapter(new ListAdapter(this, list)); listView.setOnItemClickListener(new ItemClickListener()); } 方法public List<Map<String, Object>> getData(){ } |
|
先把toast给注掉,toast要在主线程!
|
|
问题是这样的话list返回的是空置吧!
|
|
咋样就改对对了又在分线程,又得返回数据!
|
|
用线程池,Executors.newSingleThreadExecutor() 将任务提交给ExecutorService
|
|
哦,谢谢了,我没有多用过线程,我研究下线程池
|
|
用线程池,Executors.newSingleThreadExecutor() 将任务提交给ExecutorService来执行同时调用Future.get()方法来获取结果!
|
|
没有用线程池也可以,但是刚进去是没有的数据点下才出来!
|
|
就单用了上面写的线程执行,但是数据刚进去没有点下才出来,是异步的?
|