问题描述
- gridview无法更新啊,求教~~~~
-
package jx.jvtc.bestfoddServer;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;import jx.jvtc.model.CustomerBuyFood;
import jx.jvtc.model.FoodAndroid;
import jx.jvtc.webserviceimpl.Orderbuyimpl;import android.R.integer;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;public class SendMssion extends Activity {
private GridView gridListView; private List<HashMap<String, Object>> data; private String test = "多列显示Test"; List<CustomerBuyFood> lsInfo; SimpleAdapter sa; public void showFoodInfo(List<FoodAndroid> lsFoodMenu, final int id) { String[] str = new String[lsFoodMenu.size()]; for (int i = 0; i < lsFoodMenu.size(); i++) { String value = lsFoodMenu.get(i).getMaterial(); value += " × "; value += lsFoodMenu.get(i).getId() + "份"; str[i] = value; } new AlertDialog.Builder(this).setTitle("需配送的菜").setItems(str, null) .setNegativeButton("正在派送", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Thread a = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub new Orderbuyimpl().updateorder(id, 0); lsInfo = new Orderbuyimpl() .getordertime(LoginState.cellPhone); data = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < lsInfo.size(); i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("sendStateStr", lsInfo.get(i) .getOflag()); System.out .println(lsInfo.get(i).getOflag()); data.add(map); } } }); a.start(); try { a.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } gridListView = (GridView) findViewById(R.id.list_gridView); sa = (SimpleAdapter) gridListView.getAdapter(); sa.notifyDataSetChanged(); // gridListView.setAdapter(sa); } }) .setPositiveButton("已送达", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub new Orderbuyimpl().updateorder(id, 1); SendMssion.this.onResume(); } }).start(); } }).show(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread a = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub lsInfo = new Orderbuyimpl().getordertime(LoginState.cellPhone); } }); a.start(); try { a.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (lsInfo.size() == 0) { setContentView(R.layout.activity_send_mission_null); } else { setContentView(R.layout.activity_send_mssion); gridListView = (GridView) findViewById(R.id.list_gridView); fillData(); sa = new SimpleAdapter(this, data, R.layout.activity_send_mission_item, new String[] { "phone", "address", "homeSendTime", "sendStateStr", "foodMenu", "id" }, new int[] { R.id.phone, R.id.sendAddr, R.id.sendTime, R.id.sendState }); gridListView.setAdapter(sa); gridListView .setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub HashMap<String, Object> item = (HashMap<String, Object>) arg0 .getItemAtPosition(arg2); // setTitle((String) item.get("goods_text")); // String str = item.get("phone"); // Toast.makeText(SendMssion.this, "", // Toast.LENGTH_SHORT).show(); List<FoodAndroid> lsFoodMenu; lsFoodMenu = (List<FoodAndroid>) item .get("foodMenu"); // System.out.println(lsFoodMenu.size()+" ss"); int id = (Integer) item.get("id"); // System.out.println(id + "tsendState"); showFoodInfo(lsFoodMenu, id); } }); } } public void fillData() { data = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < lsInfo.size(); i++) { HashMap<String, Object> map = new HashMap<String, Object>(); int id = lsInfo.get(i).getId(); map.put("phone", lsInfo.get(i).getPhone()); map.put("address", lsInfo.get(i).getAddress()); map.put("homeSendTime", lsInfo.get(i).getStrdate()); map.put("sendStateStr", lsInfo.get(i).getOflag()); map.put("id", id); map.put("foodMenu", lsInfo.get(i).getFoodmenu()); // System.out.println(String.valueOf(lsInfo.get(i).getId()) // + " tDDDDDD"); data.add(map); } }
}