超稳定Expandablelistview,带优化,带联网
来源:互联网 发布:apache maven怎么安装 编辑:程序博客网 时间:2024/04/29 10:10
原创:刚刚需要些一个expanablelistview,后来发现需要写一个三级的listview,就把这个发上供大家参考吧。没写注释,但是很容易看懂!
package com.h.work.activity.query;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.ExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.ImageView;import android.widget.TextView;import com.google.gson.Gson;import com.holdsoft.admin.holdoa.R;import com.holdsoft.admin.holdoa.activity.BaseActivity;import com.holdsoft.admin.holdoa.bean.CheckTel;import com.holdsoft.admin.holdoa.utils.CacheUtils;import com.holdsoft.admin.holdoa.utils.MD5Encoder;import com.holdsoft.admin.holdoa.utils.NetWorkUtils;import com.holdsoft.admin.holdoa.utils.SPUtils;import com.holdsoft.admin.holdoa.utils.UrlPath;import org.xutils.common.Callback;import org.xutils.http.RequestParams;import org.xutils.x;/** * Created by 梁明伟 on 2016/8/12. * 办公电话查询 */public class PhoneActivity extends BaseActivity { private TextView title; private String s; private boolean isFirst = false; private CheckTel checkTel; private ExpandableListView ecpandable; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_phone); title = (TextView) findViewById(R.id.title_allpeopleUse); ecpandable = (ExpandableListView) findViewById(R.id.ecpandable); title.setText("办公电话查询"); initDate(); } private void initDate() { s = CacheUtils.getString(PhoneActivity.this, "PhoneTel"); if(!NetWorkUtils.isNetworkConnected()&&!s.isEmpty()) { processData(s); } if(!isFirst) { getDateFromNet(); isFirst = true; }else { processData(s); } } private void getDateFromNet() { int uid = SPUtils.getInstance(PhoneActivity.this).getInt("uid",SPUtils.CITY_LOCATION); String TOKEN = SPUtils.getInstance(PhoneActivity.this).getString("token","null"); Log.e("TAG","得到的TOKEN是这样的====" +TOKEN); String sign = null; try { sign = MD5Encoder.encode("/seek/getalltel?"+"token="+ TOKEN); } catch (Exception e) { e.printStackTrace(); }// +"&date=" + selectedData String CHAXUN_TELURL = UrlPath.CHAXUN_DIANHUA + uid + "&" + "sign=" + sign ; Log.e("TAG","得到的带token的链接是这样的====" + CHAXUN_TELURL); Log.e("TAG","没进联网逻辑里面"); RequestParams params = new RequestParams(CHAXUN_TELURL); params.setConnectTimeout(5000); x.http().get(params, new Callback.CommonCallback<String>() { @Override public void onSuccess(String result) { CacheUtils.putString(PhoneActivity.this,"PhoneTel",result); processData(result); } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } }); } private void processData(String s) { checkTel = parseJson(s); ecpandable.setAdapter(adapter); } private CheckTel parseJson(String s) { return new Gson().fromJson(s,CheckTel.class); } ExpandableListAdapter adapter = new BaseExpandableListAdapter(){ @Override public int getGroupCount() { return checkTel.getResult().size(); } @Override public int getChildrenCount(int groupPosition) { return checkTel.getResult().get(groupPosition).getDept2().get(0).getPerson().size(); } @Override public Object getGroup(int groupPosition) { return checkTel.getResult().get(groupPosition).getDept(); } @Override public Object getChild(int groupPosition, int childPosition) { return checkTel.getResult().get(groupPosition).getDept2().get(0).getPerson().get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { Holder holder1; if(convertView== null) { holder1 = new Holder(); convertView = View.inflate(PhoneActivity.this, R.layout.item_explistview, null); holder1.tv_explist_name = (TextView) convertView.findViewById(R.id.tv_explist_name); holder1.iv_explist_pic = (ImageView) convertView.findViewById(R.id.iv_explist_pic); convertView.setTag(holder1); }else { holder1 = (Holder) convertView.getTag(); } holder1.tv_explist_name.setText(checkTel.getResult().get(groupPosition).getDept()); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView== null) { holder = new ViewHolder(); convertView = View.inflate(PhoneActivity.this, R.layout.item_org, null); holder.org_name = (TextView) convertView.findViewById(R.id.tv_org_name); holder.org_pcount = (TextView) convertView.findViewById(R.id.tv_org_pcount); convertView.setTag(holder); }else { holder = (ViewHolder) convertView.getTag(); } holder.org_name.setText(checkTel.getResult().get(groupPosition).getDept2().get(0).getPerson().get(childPosition).getName()); holder.org_pcount.setText(checkTel.getResult().get(groupPosition).getDept2().get(0).getPerson().get(childPosition).getTel()); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } }; static class ViewHolder { TextView org_name,org_pcount; } static class Holder { TextView tv_explist_name; ImageView iv_explist_pic; }}
3 0
- 超稳定Expandablelistview,带优化,带联网
- 带全选的ExpandableListView
- 带浮动层的ExpandableListView
- Android---自定义带CheckBox的ExpandableListView实现
- Android之带group指示器的ExpandableListView
- Android之带group指示器的ExpandableListView
- Android 两级都带CheckBox的 ExpandableListView
- Android自带控件ExpandableListView的使用
- Android之带group指示器的ExpandableListView
- laravel 搜索分页 带参数稳定分页
- Android之IphoneTreeView带组指示器的ExpandableListView
- Android之IphoneTreeView带组指示器的ExpandableListView
- 去掉ExpandableListView的系统自带的箭头图标
- ExpandableListView自带箭头图标去除和替换
- ListView嵌套GridView 带条目标题 使用ExpandableListView解决
- ExpandableListView三级列表实现(带选择联动效果)
- Lucene 性能优化带数据
- VS2010优化(带示例图)
- 法律裁判文书的统计结果
- 分布式文件系统 FastDFS
- Apache POI操作Word概览
- 请求返回字符串的
- 进程保活
- 超稳定Expandablelistview,带优化,带联网
- VisualVM通过jstatd方式远程监控远程主机
- webstorm 下载并设置jade、less
- Graphviz#基本用法
- 警惕Mybatis的Foreach的的副作用
- js实现的LRU缓存function
- 360度民主评估反馈系统可以使用啦
- quartz定时任务框架
- 开启mysql 远程链接