android 后台处理数据+进度条
来源:互联网 发布:梦里花落知多少书包网 编辑:程序博客网 时间:2024/05/18 00:15
map中可以获取逐条数据.
package com.google.zxing.client.android.util;
import java.util.HashMap;
import java.util.Map;
public class MapUtil {
// 接收服务端的map,从map中可以获取逐条数据.
public static Map<String, String> getMap(String a) {
Map<String, String> goods = new HashMap<String, String>();
String[] str = a.trim().split("¥n/¥");
for (int i = 0; i < str.length; i++) {
String[] str1 = str[i].trim().split("¥n");
if (str1.length > 1) {
goods.put(str1[0], str1[1]);
} else {
goods.put(str1[0], "");
}
}
return goods;
}
}
/**
* 使用异步类上传数据 这里面请求服务器并且在数据传递结束后关闭了进度条
*/
private class DoPOst extends AsyncTask<Void, Integer, Void> {
String s;
// 接收服务端已Map形式传来的字符串
private Map<String, String> goods;
@Override
protected Void doInBackground(Void... arg0) {
try {
s = queryBFMW(resultNum);
Log.i("Other", "服务端查询后结果-------"+s+"------");
goods = MapUtil.getMap(s);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
dialog.dismiss();
if (s == null || "".equals(s) || "网络异常".equals(s)) {
Toast.makeText(getApplicationContext(), "抱歉,未查到数据", 1)
.show();
} else {
/**
* 接收服务端字符串,通过Key 接收Value.
*/
String checkNum = goods.get("checking");
String codeContent = goods.get("code");
String kymtContent = goods.get("kymt");
if ("0".equals(checkNum.trim())) {
Toast.makeText(Zs.this, "..........!", 1).show();
return;
} else if ("1".equals(checkNum.trim())) {
if("null".equals(kymtContent)||"".equals(kymtContent) || kymtContent == null ){
return;
}else
// if("hsm".equalsIgnoreCase(checkNum))
{
kymtNumber = Integer.parseInt(kymtContent.trim());
Log.i("Other", "-----"+kymtNumber+"----------");
}
if (codeContent == null || "".equals(codeContent)) {
Toast.makeText(getApplicationContext(), ".........",
1).show();
return;
}
if (goods != null) {
hsmEt.setText(codeContent);
}
}
else if ("2".equals(checkNum.trim())) {
Toast.makeText(getApplicationContext(), ".....", 1).show();
return;
}
else if ("3".equals(checkNum.trim())) {
Toast.makeText(getApplicationContext(), ".....!", 1).show();
return;
}
/**
* 处理其他问题
*/
else {
}
}
super.onPostExecute(result);
}
}
/**
*
* @param resultNum
* @return
*/
private String queryBFMW(String resultNum) {
String ss = resultNum;
String url = HttpUtil.BASE_URL
+ "/servlet/HsmCodeServlet?type=sjzsmw&hsmCode=" + resultNum
+ "&userID=" + userName + "&typeName=bf";
Log.i("Other", "------"+url+"-----------");
return HttpUtil.queryStringForPost(url);
}
以下为进度条实现
private AlertDialog dialog;
// 显示对话框
View view = LayoutInflater.from(getApplicationContext()).inflate(
R.layout.progress_dialog, null);
dialog = new AlertDialog.Builder(this).setView(view).create();
dialog.show();
// 初始化
DoPost doPost = new DoPost();
doPost.execute();
progress_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="@+id/progress_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/bbs_progress" />
<TextView
android:id="@+id/processText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/progress_icon"
android:layout_alignTop="@+id/progress_icon"
android:layout_toRightOf="@+id/progress_icon"
android:gravity="center"
android:text="请稍后..." >
</TextView>
</RelativeLayout>
bbs_progress.xml
<?xml version="1.0" encoding="UTF-8"?>
<rotate
android:drawable="@drawable/bbs_waiting"
android:useLevel="true"
android:fromDegrees="0.0"
android:toDegrees="360.0"
android:pivotX="50.0%"
android:pivotY="50.0%"
xmlns:android="http://schemas.android.com/apk/res/android" />
bbs_btn_check.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="@+id/progress_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/bbs_progress" />
<TextView
android:id="@+id/processText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/progress_icon"
android:layout_alignTop="@+id/progress_icon"
android:layout_toRightOf="@+id/progress_icon"
android:gravity="center"
android:text="请稍后..." >
</TextView>
</RelativeLayout>
- android 后台处理数据+进度条
- android service 后台处理一些数据
- 进度条(BackgroundWorker后台线程处理)--WPF应用
- 后台处理JSON数据
- 使用Android JobScheduler优雅的处理后台数据
- Android实现Service后台下载Notification进度条
- Android实现Service后台下载Notification进度条
- Android实现Service后台下载Notification进度条
- android后台任务处理
- C#后台处理JSON数据
- java后台数据批量处理
- android 后台post 数据
- Android模拟后台数据
- 通过Handler实现先显示进度条,后台进行数据处理,处理结束后取消进度条
- 通过Handler实现先显示进度条,后台进行数据处理,处理结束后取消进度条
- android 异步处理 后台更新
- Android--后台处理--AsyncTask类
- Android关于后台下载前台通知更新进度条的问题
- ios审核要注意的地方
- VB.NET中使用WebBrowser
- 2012年6月12日 给你一个真实的雹灾记录---龙口
- HTTP访问协议封装
- error C1189:#error:This file requires _WIN32_WINNT to be #defined at least to 0x0403
- android 后台处理数据+进度条
- 云计算鲜为人知的三大潜在风险
- 巴法络 WHR-G300N V2 掉线问题
- 无法启动此程序,因为计算机中丢失LIBMYSQL.dll ROR网页开发问题
- 对新公司的感觉
- 避免缓存的ajax传值方法
- 统计机器学习理论理解(转载)
- Android入门:单元测试
- 关于vs2008 SP1中CMFCToolBar的一些事儿