1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| package com.example.mo.yiyuan;
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.ListView; import android.widget.SimpleAdapter;
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
public class Yuyue_mainactivity extends Activity { ListView lvDepartment,lvSonDepartment; private String[] lvDepartment_text = new String[]{ "外科", "内科", "五官", "皮肤", "儿科" }; View oldDepartment; int last_item = -1;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.yuyue_mainactivity);
lvDepartment = (ListView)findViewById(R.id.lvDepartment); SimpleAdapter lvDepartmentAdapter = new SimpleAdapter( this,getDepartmentData(),R.layout.department_item,new String[]{"lvDepartment_text"},new int[]{R.id.lvDepartment_text} ); lvDepartment.setAdapter(lvDepartmentAdapter); lvSonDepartment = (ListView) findViewById(R.id.lvSonDepartment); lvDepartment.getChildAt(0).callOnClick();
lvDepartment.post(new Runnable() { @Override public void run() { ImageView ivHead = (ImageView) lvDepartment.getChildAt(0).findViewById(R.id.ivHead); ivHead.setVisibility(View.VISIBLE); lvDepartment.getChildAt(0).setBackgroundColor(getResources().getColor(R.color.white)); List<Map<String, Object>> sonList = getSonDepartmentData(lvDepartment_text[0]); SimpleAdapter lvSonDepartmentAdapter = new SimpleAdapter( getApplication(), sonList, R.layout.sondepartment_item, new String[]{"son_text"}, new int[]{R.id.son_text} ); lvSonDepartment.setAdapter(lvSonDepartmentAdapter); oldDepartment = lvDepartment.getChildAt(0); last_item = 0; } });
lvDepartment.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView ivHead = (ImageView) view.findViewById(R.id.ivHead); ivHead.setVisibility(View.VISIBLE); view.setBackgroundColor(getResources().getColor(R.color.white)); List<Map<String, Object>> sonList = getSonDepartmentData(lvDepartment_text[position]); SimpleAdapter lvSonDepartmentAdapter = new SimpleAdapter( getApplication(), sonList, R.layout.sondepartment_item, new String[]{"son_text"}, new int[]{R.id.son_text} ); lvSonDepartment.setAdapter(lvSonDepartmentAdapter); if (last_item != -1 && last_item != position) { oldDepartment.findViewById(R.id.ivHead).setVisibility(View.INVISIBLE); oldDepartment.setBackgroundColor(getResources().getColor(R.color.transparent));
lvSonDepartmentAdapter.notifyDataSetChanged(); } oldDepartment = view; last_item = position; } });
lvSonDepartment.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent it = new Intent(getApplicationContext(),Yuyue_SonDepartment.class); startActivity(it); } }); }
private List<Map<String,Object>> getDepartmentData(){ List<Map<String,Object>> list = new ArrayList<Map<String, Object>>(); for (int i=0;i<lvDepartment_text.length;i++){ Map<String,Object> map = new HashMap<String, Object>(); map.put("lvDepartment_text",lvDepartment_text[i]); list.add(map); } return list; }
private List<Map<String,Object>> getSonDepartmentData(String str){ List<Map<String,Object>> list = new ArrayList<Map<String, Object>>(); for (int i=0;i<10;i++){ Map<String,Object> map = new HashMap<String, Object>(); map.put("son_text",str + i); list.add(map); } return list; }
}
|