掌上快递之主界面篇(3)

简介:

概述

这篇比较简单,就是收藏自己的快递信息以后随便查阅进度,界面找了一些小logo显得比较干净整洁,数据库部分处理是使用了Xutil中的DbUtils部分来处理


1、快递收藏效果

在MyExpressActivity.Java中的写了一个适配器

MyExpressAdapter adapter;,进入MyExpressAdapter.java中可以看出它继承BaseAdapter,其中核心是在getview部分

[java]  view plain  copy
  1. @Override  
  2.     public View getView(int position, View convertView, ViewGroup parent) {  
  3.         // TODO Auto-generated method stub  
  4.          ViewHolder holder;  
  5.            
  6.          if (convertView == null) {  
  7.             <span style="color:#009900;"> convertView = mInflater.inflate(R.layout.my_express_item,parent, false);</span>  
  8.              holder = new ViewHolder();  
  9.              holder.remarkName = (TextView) convertView.findViewById(R.id.tv_remark_name);  
  10.              holder.expressNameAndNumber = (TextView) convertView.findViewById(R.id.tv_express_name_number);  
  11.              holder.newInfo = (TextView) convertView.findViewById(R.id.tv_new_context);  
  12.              holder.newTime = (TextView) convertView.findViewById(R.id.tv_new_time);  
  13.              convertView.setTag(holder);  
  14.         } else {  
  15.             holder = (ViewHolder) convertView.getTag();  
  16.         }  
  17.         holder.remarkName.setText(lists.get(position).getName());  
  18.         holder.expressNameAndNumber.setText(lists.get(position).getExpressName() + "  " + lists.get(position).getExpressNumber());  
  19.         holder.newInfo.setText(lists.get(position).getNewInfo());  
  20.         holder.newTime.setText(lists.get(position).getNewDate());  
  21.         return convertView;  
  22.     }  


在面绿色的布局文件中,就是这个效果的核心所在

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:orientation="vertical"  
  6.      xmlns:baiduadsdk="http://schemas.android.com/apk/res/com.weimeijing.feigeshudi"  
  7.      >  
  8.   
  9.     <TextView  
  10.         android:id="@+id/tv_remark_name"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="wrap_content"  
  13.         android:gravity="center"  
  14.         android:text="备注名称"  
  15.         android:textColor="#FF000000"  
  16.         android:textSize="15dp" />  
  17.   
  18.     <TextView  
  19.         android:id="@+id/tv_express_name_number"  
  20.         android:layout_width="wrap_content"  
  21.         android:layout_height="wrap_content"  
  22.         android:text="快递名称 + 单号"  
  23.         android:background="@drawable/mark"  
  24.        android:textColor="@color/white"  
  25.         android:textSize="13dp" />  
  26.     <TextView  
  27.         android:id="@+id/tv_new_context"  
  28.         android:layout_width="match_parent"  
  29.         android:layout_height="wrap_content"  
  30.         android:text="最新信息"  
  31.         android:textColor="#FF000000"  
  32.         android:textSize="17dp" />  
  33.     <TextView  
  34.         android:id="@+id/tv_new_time"  
  35.         android:layout_width="match_parent"  
  36.         android:layout_height="wrap_content"  
  37.         android:text="最新时间"  
  38.         android:textColor="#FF353535"  
  39.         android:textSize="13dp" />  
  40.               
  41. </LinearLayout>  


2、逻辑处理

在MyExpressActivity.java利用Xutil中的DbUtils部分来处理,来完成增删改查

[java]  view plain  copy
  1. package com;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import com.lidroid.xutils.DbUtils;  
  7. import com.lidroid.xutils.db.sqlite.Selector;  
  8. import com.lidroid.xutils.exception.DbException;  
  9. import com.weimeijing.feigeshudi.R;  
  10. import com.adapter.MyExpressAdapter;  
  11. import com.bean.ExpressHistory;  
  12. import com.util.QueryExpressUtil;  
  13.   
  14. import android.app.AlertDialog;  
  15. import android.app.ProgressDialog;  
  16. import android.content.DialogInterface;  
  17. import android.content.Intent;  
  18. import android.net.Uri;  
  19. import android.os.Bundle;  
  20. import android.support.v4.app.Fragment;  
  21. import android.util.Log;  
  22. import android.view.LayoutInflater;  
  23. import android.view.TextureView;  
  24. import android.view.View;  
  25. import android.view.ViewGroup;  
  26. import android.widget.AdapterView;  
  27. import android.widget.AdapterView.OnItemClickListener;  
  28. import android.widget.AdapterView.OnItemLongClickListener;  
  29. import android.widget.EditText;  
  30. import android.widget.ListView;  
  31. import android.widget.TextView;  
  32. import android.widget.Toast;  
  33.   
  34. public class MyExpressActivity extends Fragment {  
  35.     private ListView myExpress;  
  36.     private List<ExpressHistory> infoList;  
  37.     private ProgressDialog progressDialog;  
  38.     MyExpressAdapter adapter;  
  39.     private ExpressHistory isExist;  
  40.     DbUtils db;  
  41.     private String number;  
  42.     private TextView count;  
  43.   
  44.     @Override  
  45.     public View onCreateView(LayoutInflater inflater, ViewGroup container,  
  46.             Bundle savedInstanceState) {  
  47.         return inflater.inflate(R.layout.activity_my_express, container, false);  
  48.   
  49.     }  
  50.   
  51.     @Override  
  52.     public void onActivityCreated(Bundle savedInstanceState) {  
  53.         super.onActivityCreated(savedInstanceState);  
  54.         <span style="color:#33CC00;">db = DbUtils.create(getActivity());</span>  
  55.         myExpress = (ListView) getView().findViewById(R.id.lv_my_express);  
  56.         // count计数  
  57.         count = (TextView) getView().findViewById(R.id.count);  
  58.         try {  
  59.             infoList = db.findAll(Selector.from(ExpressHistory.class));  
  60.             if (infoList == null) {  
  61.                 count.setText("0");  
  62.             } else {  
  63.                 count.setText("" + infoList.size());  
  64.             }  
  65.         } catch (DbException e2) {  
  66.             // TODO Auto-generated catch block  
  67.             e2.printStackTrace();  
  68.         }  
  69.         myExpress.setOnItemClickListener(new OnItemClickListener() {  
  70.   
  71.             @Override  
  72.             public void onItemClick(AdapterView<?> parent, View view,  
  73.                     int position, long id) {  
  74.   
  75.                 Log.v("setOnItemClickListener""setOnItemClickListener");  
  76.                 progressDialog = new ProgressDialog(getActivity());  
  77.                 number = infoList.get(position).getExpressNumber();  
  78.                 String name = infoList.get(position).getExpressName();  
  79.                 String code = infoList.get(position).getExpressCode();  
  80.                 QueryExpressUtil.queryExpressForNumber(number, name, code,  
  81.                         getActivity(), progressDialog);  
  82.   
  83.             }  
  84.         });  
  85.         myExpress.setOnItemLongClickListener(new OnItemLongClickListener() {  
  86.   
  87.             @Override  
  88.             public boolean onItemLongClick(AdapterView<?> parent, View view,  
  89.                     final int position, long id) {  
  90.                 // TODO Auto-generated method stub  
  91.                 Log.v("setOnItemLongClickListener",  
  92.                         "setOnItemLongClickListener");  
  93.                 new AlertDialog.Builder(getActivity())  
  94.                         .setTitle("操作")  
  95.                         .setItems(R.array.arrcontent,  
  96.                                 new DialogInterface.OnClickListener() {  
  97.                                     public void onClick(DialogInterface dialog,  
  98.                                             int which) {  
  99.                                         final String[] PK = getResources()  
  100.                                                 .getStringArray(  
  101.                                                         R.array.arrcontent);  
  102.                                         if (PK[which].equals("修改备注")) {  
  103.                                             final EditText editText = new EditText(  
  104.                                                     getActivity());  
  105.                                             new AlertDialog.Builder(  
  106.                                                     getActivity())  
  107.                                                     .setTitle("请输入备注名称")  
  108.                                                     .setIcon(  
  109.                                                             android.R.drawable.ic_dialog_info)  
  110.                                                     .setView(editText)  
  111.                                                     .setPositiveButton(  
  112.                                                             "确定",  
  113.                                                             new DialogInterface.OnClickListener() {  
  114.   
  115.                                                                 @Override  
  116.                                                                 public void onClick(  
  117.                                                                         DialogInterface dialog,  
  118.                                                                         int which) {  
  119.                                                                     number = infoList  
  120.                                                                             .get(position)  
  121.                                                                             .getExpressNumber();  
  122.                                                                     // TODO  
  123.                                                                     // Auto-generated  
  124.                                                                     // method  
  125.                                                                     // stub  
  126.                                                                     try {  
  127.                                                                         isExist = db  
  128.                                                                                 .findFirst(Selector  
  129.                                                                                         .from(ExpressHistory.class)  
  130.                                                                                         .where("expressnumber",  
  131.                                                                                                 "=",  
  132.                                                                                                 number));  
  133.                                                                     } catch (DbException e1) {  
  134.                                                                         // TODO  
  135.                                                                         // Auto-generated  
  136.                                                                         // catch  
  137.                                                                         // block  
  138.                                                                         e1.printStackTrace();  
  139.                                                                     }  
  140.                                                                     isExist.setName(editText  
  141.                                                                             .getText()  
  142.                                                                             .toString());  
  143.                                                                     try {  
  144.                                                                         db.update(isExist);  
  145.                                                                     } catch (DbException e1) {  
  146.                                                                         // TODO  
  147.                                                                         // Auto-generated  
  148.                                                                         // catch  
  149.                                                                         // block  
  150.                                                                         e1.printStackTrace();  
  151.                                                                     }  
  152.                                                                     adapter = (MyExpressAdapter) myExpress  
  153.                                                                             .getAdapter();  
  154.                                                                     adapter.notifyDataSetChanged();// 实现数据的实时刷新  
  155.                                                                 }  
  156.                                                             })  
  157.                                                     .setNegativeButton(  
  158.                                                             "取消",  
  159.                                                             new DialogInterface.OnClickListener() {  
  160.                                                                 @Override  
  161.                                                                 public void onClick(  
  162.                                                                         DialogInterface dialog,  
  163.                                                                         int which) {  
  164.                                                                     // TODO  
  165.                                                                     // Auto-generated  
  166.                                                                     // method  
  167.                                                                     // stub  
  168.                                                                     dialog.cancel();  
  169.                                                                 }  
  170.                                                             }).create().show();  
  171.   
  172.                                         }  
  173.                                         if (PK[which].equals("删除")) {  
  174.                                             String number = infoList.get(  
  175.                                                     position)  
  176.                                                     .getExpressNumber();  
  177.                                             Log.v("number", number);  
  178.                                             try {  
  179.                                                 isExist = db  
  180.                                                         .findFirst(Selector  
  181.                                                                 .from(ExpressHistory.class)  
  182.                                                                 .where("expressnumber",  
  183.                                                                         "=",  
  184.                                                                         number));  
  185.                                             } catch (DbException e1) {  
  186.                                                 // TODO Auto-generated catch  
  187.                                                 // block  
  188.                                                 e1.printStackTrace();  
  189.                                             }  
  190.                                             try {  
  191.                                                 db.deleteById(  
  192.                                                         ExpressHistory.class,  
  193.                                                         isExist.getId());  
  194.                                             } catch (DbException e) {  
  195.                                                 // TODO Auto-generated catch  
  196.                                                 // block  
  197.                                                 e.printStackTrace();  
  198.                                             }  
  199.                                             infoList.remove(position);  
  200.                                             adapter = (MyExpressAdapter) myExpress  
  201.                                                     .getAdapter();  
  202.                                             if (!adapter.isEmpty()) {  
  203.                                                 adapter.notifyDataSetChanged(); // 实现数据的实时刷新  
  204.                                             }  
  205.                                             Toast.makeText(getActivity(),  
  206.                                                     PK[which] + "成功",  
  207.                                                     Toast.LENGTH_LONG).show();  
  208.                                         }  
  209.                                         if (PK[which].equals("通过短信发送")) {  
  210.                                             Uri uri = Uri.parse("smsto:");  
  211.   
  212.                                             Intent intent = new Intent(  
  213.                                                     Intent.ACTION_SENDTO, uri);  
  214.   
  215.                                             intent.putExtra(  
  216.                                                     "sms_body",  
  217.                                                     infoList.get(position)  
  218.                                                             .getNewDate()  
  219.                                                             + "  "  
  220.                                                             + infoList  
  221.                                                                     .get(position)  
  222.                                                                     .getNewInfo());  
  223.   
  224.                                             startActivity(intent);  
  225.                                         }  
  226.                                     }  
  227.                                 })  
  228.                         .setNegativeButton("取消",  
  229.                                 new DialogInterface.OnClickListener() {  
  230.                                     public void onClick(DialogInterface dialog,  
  231.                                             int which) {  
  232.                                         // TODO Auto-generated method stub  
  233.   
  234.                                     }  
  235.                                 }).show();  
  236.                 return true;  
  237.   
  238.             }  
  239.   
  240.         });  
  241.     }  
  242.   
  243.     @Override  
  244.     public void onResume() {  
  245.         // TODO Auto-generated method stub  
  246.         super.onResume();  
  247.         DbUtils db = DbUtils.create(getActivity());  
  248.         // List<ExpressHistory> infoList = null;  
  249.         try {  
  250.             infoList = db.findAll(ExpressHistory.class);  
  251.         } catch (DbException e) {  
  252.             // TODO Auto-generated catch block  
  253.             e.printStackTrace();  
  254.         }  
  255.         if (infoList == null || infoList.size() == 0) {  
  256.             Toast.makeText(getActivity(), "当前还没有保存任何快递哦,保存后再来这里查看吧!",  
  257.                     Toast.LENGTH_SHORT).show();  
  258.         } else {  
  259.             MyExpressAdapter adapter = new MyExpressAdapter(getActivity(),  
  260.                     (ArrayList<ExpressHistory>) infoList);  
  261.             myExpress.setAdapter(adapter);  
  262.         }  
  263.   
  264.     }  
  265.   
  266.     @Override  
  267.     public void onPause() {  
  268.         super.onPause();  
  269.     }  
  270.   
  271. }  


转载:http://blog.csdn.net/xsf50717/article/details/47253495

目录
相关文章
|
8月前
KTV点歌程序
KTV点歌程序
72 0
|
SQL 安全 JavaScript
基于JavaWeb的电影院在线选座订票管理系统
基于JavaWeb的电影院在线选座订票管理系统
602 0
基于JavaWeb的电影院在线选座订票管理系统
|
3天前
|
JavaScript Java 测试技术
基于小程序的民宿预订系统(2024全新定制)
基于小程序的民宿预订系统(2024全新定制)
6 0
|
13天前
|
供应链 安全 数据挖掘
外卖跑腿系统开发详情丨校园外卖跑腿系统开发指南
开发外卖跑腿系统旨在服务于外卖平台和跑腿服务商,实现用户下单、骑手接单及订单管理等功能。系统包括用户端应用(注册、下单、支付等)、商家管理(菜单更新、订单处理)、骑手端应用(任务接收、配送)以及实时订单管理。此外,系统支持多种支付方式、订单结算、评价反馈机制、数据统计报表和客户服务,确保交易安全、提升效率并优化用户体验。
|
1月前
|
存储 安全 JavaScript
萌宠宜家商城系统
萌宠宜家商城系统
|
10月前
|
小程序 搜索推荐
附源码-基于Web的民宿预约系统的设计与实现,房间预订、旅游订票
重要的事情说三遍,可白嫖,可白嫖,可白嫖!!! 源码下载链接:docs.qq.com/doc/DYm5DSlBWZEplalBP
|
10月前
|
小程序
【带源码】基于微信小程序的旅游订票旅游预订小程序酒店预订项目
重要的事情说三遍,可白嫖,可白嫖,可白嫖!!! 源码下载链接:docs.qq.com/doc/DYm5DSlBWZEplalBP 随着移动互联网的迅速发展,人们对于旅游信息获取和旅行订票的需求也逐渐增加。传统的旅游指南和订票方式往往不够便捷和灵活,而微信作为一种广泛使用的社交媒体平台,拥有巨大的用户群体和强大的社交属性,成为了传递信息和服务的重要渠道。
|
缓存 算法 数据挖掘
东郊到家系统程序开发预约上门软件功能
目前主流的按摩软件系统会有三个端口:用户端、技师端、商家端,以及管理后台。
|
网络协议 测试技术 Go
家庭收支软件需求和界面|学习笔记
快速学习家庭收支软件需求和界面
104 0
家庭收支软件需求和界面|学习笔记
|
前端开发
移动端支付界面制作(小兔鲜项目)
移动端支付界面制作(小兔鲜项目)
184 0
移动端支付界面制作(小兔鲜项目)