80,351
社区成员
发帖
与我相关
我的任务
分享
/*
* 获取服务器订单
* @param String url, HashMap<String,Object> data
* @void
*/
public void getOrders(String url,HashMap<String,Object> param) throws Exception
{
String data = RedefineHttpRequest.HttpPost(url, param); //取得服务器返回的json
JSONObject msg = new JSONObject(data);
int error = msg.getInt("error");
switch (error)
{
case 0: //返回正确
JSONArray arr = msg.getJSONArray("data");
if(arr.length()==0) //订单数组为空
{
}
else
{
List<HashMap<String,Object>> res = new ArrayList<HashMap<String,Object>>(); //定义订单集合数组
for(int i=0;i<arr.length();i++)
{
HashMap<String,Object> map = new HashMap<String,Object>();
JSONObject order = arr.getJSONObject(i); //取得每一个订单
map.put("order_id", order.getInt("order_id"));
map.put("goods_name",order.getString("goods_name"));
map.put("amount", order.getDouble("amount"));
res.add(map); //添加到集合数组
}
SimpleAdapter _Adapter = new SimpleAdapter(this.getActivity(), res ,R.layout.index_order,
new String[]{"order_id"},
new int[]{R.id.order_id}
);
try
{
orderListView.setAdapter(_Adapter); //执行失败,编译通过
}
catch(Exception e)
{
android.util.Log.i("notice",e.toString());
}
}
break;
case 1: //返回错误
break;
case 2: //未登录
break;
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="@+id/order_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#55555555"
/>
</RelativeLayout>