Activity界面 刷新 状态提示,在线等
我进一Activity时,此界面开始会取服务器数据,然后显示到界面上来,所以当数据显示出来时,会有点加载时间,(默认情况下,界面右上角,有 刷新 二字)
现需:
1 刚进界面时,当数据正在加载时,在界面右上角用一 正在刷新或正在加载的 图标 来提示,当数据加载完成后,又显示默认时的 刷新 二字
2 当页面数据加载完成后,再点击右上角的 刷新 处,右上角 又出现 正在刷新或正在加载的图片,直到数据加载完成
这如何实现呀,能给个demo就更好, 350038760@qq.com thanks
[解决办法]
线程+handler吧,有时间的话写个demo吧
[解决办法]
Android有异步任务啊!
[解决办法]
pDialog = new ProgressDialog(ParkListActivity.this); pDialog.setMessage("获取数据中,请稍等..."); handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); pDialog.dismiss(); if (msg.what == 0) { Toast.makeText(ParkListActivity.this, "获取数据失败", Toast.LENGTH_LONG) .show(); } else { if (msg.obj == null) { Toast.makeText(ParkListActivity.this, "获取数据失败", Toast.LENGTH_LONG).show(); } else { ParkListReturnInfo parkListReturnInfo = null; parkListReturnInfo = (ParkListReturnInfo) msg.obj; if (parkListReturnInfo != null && parkListReturnInfo.getReturnCode() != null && parkListReturnInfo.getReturnCode().equals( "0")) { list1 = parkListReturnInfo.getParkListReturnData(); mantitle.setText(area+"区"+parkName+"共搜索到"+list1.size()+"个停车场"); if (list1 != null && list1.size() > 0) { Map<String, Object> map; Iterator<ParkListReturnData> it = list1 .iterator(); while (it.hasNext()) { ParkListReturnData parkListReturnData1 = it .next(); map = new HashMap<String, Object>(); map.put("name", parkListReturnData1 .getParkName()); map.put("sex", parkListReturnData1 .getFreeSeat()); map.put("dfs", parkListReturnData1 .getOrderFreeSeat()); map.put("aaa", parkListReturnData1 .getParkId()); System.out.println("88888888888" + parkListReturnData1.getParkId()); listput.add(map); // parkListReturnData1.getParkId(); } } listadapter = new ListAdapter(ParkListActivity.this, listput); listView.setAdapter(listadapter); } else { Toast.makeText(ParkListActivity.this, parkListReturnInfo.getReturnName(), Toast.LENGTH_LONG).show(); } } } pDialog.dismiss(); } }; pDialog.show(); QueryThread th = new QueryThread(this.handler); th.start();
[解决办法]
public class ParkListActivity extends CommonActivity { ListView listView; public static List<Map<String, Object>> listput; ListAdapter listadapter; ProgressDialog pDialog; TextView title; TextView mantitle; Handler handler;@Override public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.park_list);pDialog = new ProgressDialog(ParkListActivity.this); pDialog.setMessage("获取数据中,请稍等..."); handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); pDialog.dismiss(); if (msg.what == 0) { Toast.makeText(ParkListActivity.this, "获取数据失败", Toast.LENGTH_LONG) .show(); } else { if (msg.obj == null) { Toast.makeText(ParkListActivity.this, "获取数据失败", Toast.LENGTH_LONG).show(); } else { ParkListReturnInfo parkListReturnInfo = null; parkListReturnInfo = (ParkListReturnInfo) msg.obj; 对后台的数据进行处理(省略) } } pDialog.dismiss(); } }; pDialog.show(); QueryThread th = new QueryThread(this.handler); th.start();}class QueryThread extends Thread { private Handler handler; private ParkClient parkClient; private ParkListReturnInfo parkListReturnInfo; private ParkListInfo parkListInfo; private Message msg; public QueryThread(Handler handler) { this.handler = handler; } @Override public void run() { msg = new Message(); parkListReturnInfo = parkClient.getParkList(parkListInfo);//获取后台数据 msg.obj = parkListReturnInfo; msg.what = 1; } catch (Exception e) { msg.what = 0; e.printStackTrace(); } finally { handler.sendMessage(msg); } } }}
[解决办法]