2010.12.29——— android 可伸缩的listview ExpandableList

直接上代码吧 比较简单 大家看一下就明白了


  package com.huitu.project;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import com.huitu.pojo.ZFSCLX;import com.huitu.service.ZFSCLXService;import com.huitu.util.JSONUtil;import android.app.AlertDialog;import android.app.ExpandableListActivity;import android.app.ProgressDialog;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.KeyEvent;import android.view.View;import android.widget.ExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.SimpleExpandableListAdapter;public class ZFSCMainActivity extends ExpandableListActivity {private ExpandableListAdapter mAdapter;private ProgressDialog pd;private Handler handler;private List<Map<String, Object>> groupData = new ArrayList<Map<String, Object>>();    private List<List<Map<String, Object>>> childData = new ArrayList<List<Map<String, Object>>>();        @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        pd = new ProgressDialog(this);pd.setIndeterminate(true);pd.setMessage("加载数据...");pd.setCancelable(true);pd.show();        handler = new Handler(){         @Override             public void handleMessage(Message msg) {         int length = msg.getData().getInt("length");             switch (length){             case 1 :             pd.dismiss();         setListAdapter(mAdapter);         break;             case 2 :             pd.dismiss();            new AlertDialog.Builder(ZFSCMainActivity.this)    .setMessage("网络异常!")           .setCancelable(false)           .setPositiveButton("确定", new DialogInterface.OnClickListener() {               public void onClick(DialogInterface dialog, int id) {               //finish();               }           }).create().show();    break;                      }         }        };                new Thread(){        Message msg = new Message();        public void run(){        try{        String json = ZFSCLXService.queryZFSCLX(null);        System.out.println(json);        List<ZFSCLX> list_zfsclx= JSONUtil.parseJSON_ZFSCLX_list(json);                        for (ZFSCLX bean : list_zfsclx) {                    Map<String, Object> curGroupMap = new HashMap<String, Object>();                    groupData.add(curGroupMap);                    curGroupMap.put("name", bean.getName());                    curGroupMap.put("id",bean.getId());                    curGroupMap.put("pid",bean.getP_Id());                                        String json2 = ZFSCLXService.queryZFSCLX(bean.getId());            System.out.println(json2);            List<ZFSCLX> zfsclxitems= JSONUtil.parseJSON_ZFSCLX_list(json2);                    List<Map<String, Object>> children = new ArrayList<Map<String, Object>>();                    for (ZFSCLX bean2 : zfsclxitems) {                        Map<String, Object> curChildMap = new HashMap<String, Object>();                        children.add(curChildMap);                        curChildMap.put("name", bean2.getName());                        curChildMap.put("id",bean2.getId());                        curChildMap.put("pid",bean2.getP_Id());                    }                    childData.add(children);                }             // Set up our adapter                mAdapter = new SimpleExpandableListAdapter(                ZFSCMainActivity.this,                        groupData,                        android.R.layout.simple_expandable_list_item_1,                        new String[] { "name" },                        new int[] { android.R.id.text1 },                        childData,                        android.R.layout.simple_expandable_list_item_1,                        new String[] { "name" },                        new int[] { android.R.id.text1 }                        );                msg.getData().putInt("length", 1);    handler.sendMessage(msg);        }catch(Exception e){        e.printStackTrace();        msg.getData().putInt("length", 2);    handler.sendMessage(msg);        }        }        }.start();                                    }        @Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// 按下键盘上返回按钮if (keyCode == KeyEvent.KEYCODE_BACK) {new AlertDialog.Builder(this).setMessage("确定退出系统吗?").setNegativeButton("取消",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int which) {}}).setPositiveButton("确定",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int whichButton) {finish();}}).show();return true;} else {return super.onKeyDown(keyCode, event);}}@Overrideprotected void onDestroy() {super.onDestroy();// 或者下面这种方式//System.exit(0);//建议用这种android.os.Process.killProcess(android.os.Process.myPid());}@Overridepublic boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {String ID = (String)groupData.get(groupPosition).get("id");Intent intent = new Intent(ZFSCMainActivity.this,ZFSCActivity.class);Bundle bundle = new Bundle();bundle.putString("ID", ID);bundle.putInt("g_index", groupPosition);bundle.putInt("c_index", childPosition);bundle.putString("CID", childData.get(groupPosition).get(childPosition).get("id").toString());intent.putExtras(bundle);startActivity(intent);return super.onChildClick(parent, v, groupPosition, childPosition, id);}}



更多相关文章

  1. 2010.12.29——— android 可伸缩的listview ExpandableList
  2. android 点击返回键退出程序的方法
  3. android弹出对话框大全
  4. 2010.12.29(2)——— android GridView
  5. Android
  6. 2010.12.29(2)——— android GridView
  7. Android之——实现应用卸载功能
  8. android权限管理
  9. android之PopUpWindow显示Listview(文件列表)

随机推荐

  1. Android中retrofit网络请求框架使用
  2. 由Android4.4收起写sdcard文件权限想到的
  3. 9款Android常用的快速开发框架
  4. Android高手进阶教程(七)之----Android(
  5. Android消息推送
  6. android hidl简单实例1
  7. android TV广播监听usb和U盘的挂载
  8. 初试Android高性能编程OpenCL
  9. Android五种数据存储方式
  10. Android在layout xml中使用include