xListView
来源:互联网 发布:mac尝试靠近无线路由器 编辑:程序博客网 时间:2024/06/14 00:45
package com.bwie.yukao;
import java.io.IOException;
import java.text.SimpleDateFormat;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.com.cctest.view.XListView;
import org.com.cctest.view.XListView.IXListViewListener;
import com.bwei.bean.Bean;
import com.google.gson.Gson;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public class MainActivity extends ActionBarActivity {
private String uri=”http://172.17.29.120/localuser/loupengfei/kaoshi/data.json”;
private String paths=”http://172.17.29.120/localuser/loupengfei/kaoshi”;
private XListView xListView;
private Bean[] bean;
//private List list=new ArrayList();
int j;
private Handler mhandler;
private MyAdapter adapter;
@SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getActionBar().hide(); xListView=(XListView) findViewById(R.id.lv); new Thread(){ public void run() { getdata(); } }.start(); mhandler = new Handler() { public void handleMessage(android.os.Message msg) { bean = (Bean[]) msg.obj; for (Bean bean2 : bean) { System.out.println(bean2); } // 激活加载更多 adapter=new MyAdapter(getApplicationContext(), bean); xListView.setAdapter(adapter); xListView.setPullLoadEnable(true); // 激活下拉刷新 xListView.setPullRefreshEnable(true); // 设置xlistView上拉加载下拉刷新的监听 xListView.setXListViewListener(new IXListViewListener() { @Override // 下拉刷新的回调方法 public void onRefresh() { adapter.notifyDataSetChanged(); //设置刷新时间 xListView.setRefreshTime(dateFormat()); //停止加载更多 xListView.stopLoadMore(); //停止刷新 xListView.stopRefresh(); } @Override // //上拉加载的回调方法 public void onLoadMore() { adapter.notifyDataSetChanged(); //停止加载更多 xListView.stopLoadMore(); //停止刷新 xListView.stopRefresh(); } }); } }; // xListView.setAdapter(new MyAdapter(getApplicationContext(), bean)); xListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // TODO Auto-generated method stub Intent mIntent=new Intent(getApplicationContext(), XiangqingActivity.class); mIntent.putExtra("iv", paths+bean[position].getImageurl()); mIntent.putExtra("name", bean[position].getFoodtitle()); mIntent.putExtra("foodcontent",bean[position].getFoodcontent()); mIntent.putExtra("price",bean[position].getFoodprice()); startActivity(mIntent); } }); } private void getdata() { // TODO Auto-generated method stub // /得到HttpClient对象 HttpClient httpClient = new DefaultHttpClient(); // 得到连接方式对象,设置请求路径 HttpGet httpGet = new HttpGet(uri); try { // GET方式请求接口,得到响应内容 HttpResponse httpResponse = httpClient.execute(httpGet); // 得到状态行 StatusLine statusLine = httpResponse.getStatusLine(); // 得到状态码 int statusCode = statusLine.getStatusCode(); // 如果状态码等于200,代表请求成功 if (statusCode == 200) { // 得到包含着数据的实体 HttpEntity entity = httpResponse.getEntity(); // 讲实体转换成String,并设置编码集 String data = EntityUtils.toString(entity,"gbk"); // System.out.println(data); // 解析json Gson gson = new Gson(); Bean[] bean = gson.fromJson(data,Bean [].class); //System.out.println(bean1); Message msg = Message.obtain(); msg.obj = bean; mhandler.sendMessage(msg); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private String dateFormat() { long currentTimeMillis = System.currentTimeMillis(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String format = dateFormat.format(currentTimeMillis); return format; }}
- XListView
- XListView
- Xlistview
- XListView
- xListView
- XListView
- xlistview
- xListView
- XlistView
- xlistview
- xlistview
- XListView
- xlistview
- xListview
- XListView
- XListView
- xlistview
- xlistview
- 移植dhclient到arm linux
- 工作学习生活计划
- 正则表达式学习(一)认识正则表达式
- struts2 + hibernate整合小项目
- Nginx location的配置-----三叉排序树
- xListView
- Node.js调用本地摄像头拍摄上传
- Net Framework4.0安装失败解决之道
- CSS 的优先级机制
- appCan开发:oninput实现动态请求搜索功能例子
- Nginx 配置初始化过程
- App 移动应用中九种导航设计总结及其优缺点分析
- JAVA虚拟机学习实践-IBM HeapAnalyzer
- 从零基础接触java第九章第三节