真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android二級列表

android中二級列表的顯示與ListView、RecyelerView等步驟類似:

目前創(chuàng)新互聯(lián)已為上1000+的企業(yè)提供了網(wǎng)站建設、域名、虛擬空間、綿陽服務器托管、企業(yè)網(wǎng)站設計、滄縣網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

(1)xml布局

(2)代碼:

private ExpandableListView expandablelistview;// 可擴展的二級列表
//創(chuàng)建對象
expandablelistview = (ExpandableListView) findViewById(R.id.expandablelistview);
//實現(xiàn)二級列表的Group點擊效果
expandablelistview.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				if (!parent.isGroupExpanded(groupPosition)) {
					departmentId = (String) tree.get(groupArray
							.get(groupPosition));
				getemployee(groupPosition);// 獲取部門下的員工信息
					if (pos != groupPosition) {
						parent.collapseGroup(pos);
					}
					pos = groupPosition;
				} else {
					parent.collapseGroup(groupPosition);
				}
				return true;
			}
		});		

(3)適配器:

public class ExpandableAdapter extends BaseExpandableListAdapter {

		public ExpandableAdapter() {
			hand = new Handler() {

				@Override
				public void handleMessage(Message msg) {
					notifyDataSetChanged();
					super.handleMessage(msg);
				}
			};
		}

		public Object getChild(int groupPosition, int childPosition) {
			if (childArray.size() == 0) {
				return null;
			}
			return childArray.get(groupPosition).get(childPosition);
		}

		public long getChildId(int groupPosition, int childPosition) {
			return childPosition;
		}

		public int getChildrenCount(int groupPosition) {
			// if (childArray.size() == 0) {
			// return 0;
			// }
			// if (childArray.size() == 1) {
			// return 1;
			// }
			return childArray.size();
		}

		public View getChildView(int groupPosition, int childPosition,
				boolean isLastChild, View convertView, ViewGroup parent) {
			if (childArray.size() == 0) {
				return getGenericView("無員工信息");
			}
			if (childArray.size() == 1) {
				return getGenericViewchild(childArray.get(0).get(0));
			}
			String string = childArray.get(groupPosition).get(childPosition);
			return getGenericViewchild(string);
		}

		// group method stub
		public Object getGroup(int groupPosition) {
			return groupArray.get(groupPosition);
		}

		public int getGroupCount() {
			return groupArray.size();
		}

		public long getGroupId(int groupPosition) {
			return groupPosition;
		}

		public View getGroupView(int groupPosition, boolean isExpanded,
				View convertView, ViewGroup parent) {
			String string = groupArray.get(groupPosition);
			return getGenericView(string);
		}

		// View stub to create Group/Children 's View
		public TextView getGenericView(String string) {
			// Layout parameters for the ExpandableListView
			AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
					ViewGroup.LayoutParams.FILL_PARENT,
					ViewGroup.LayoutParams.FILL_PARENT);
			TextView text = new TextView(Manager_Employee_List.this);
			text.setLayoutParams(layoutParams);
			// Center the text vertically
			text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
			// Set the text starting position
			text.setPadding(100, 0, 0, 0);
			text.setTextSize(25);
			text.setBackgroundResource(R.drawable.back_top);
			text.setText(string);
			return text;
		}

		public View getGenericViewchild(final String string) {
			View v = View.inflate(Manager_Employee_List.this,
					R.layout.activity_baseadapter_list, null);
			TextView text = (TextView) v.findViewById(R.id.tv_baseadapter_list);
			ImageButton alter = (ImageButton) v
					.findViewById(R.id.ib_baseadapter_alter);
			// 修改
			alter.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Toast.makeText(getApplicationContext(), "修改", 0).show();
					Intent intent_Alter = new Intent(
							Manager_Employee_List.this, Manager_Add.class);
					intent_Alter.putExtra("companyId", companyId);
					PeopleNameAlter peopleNameAlter = (PeopleNameAlter) treeMap
							.get(string);
					intent_Alter.putExtra("biaoshi", true);
					intent_Alter.putExtra("banc", peopleNameAlter.banc);
					intent_Alter.putExtra("dapart", peopleNameAlter.dapart);
					intent_Alter.putExtra("id", peopleNameAlter.id);
					intent_Alter.putExtra("loginname",
							peopleNameAlter.loginname);
					intent_Alter.putExtra("phone", peopleNameAlter.phone);
					intent_Alter.putExtra("pwd", peopleNameAlter.pwd);
					intent_Alter.putExtra("name", string);
					startActivity(intent_Alter);
				}
			});
			ImageButton delete = (ImageButton) v
					.findViewById(R.id.ib_baseadapter_delete);
			// 刪除
			delete.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Toast.makeText(getApplicationContext(), "刪除", 0).show();
					PeopleNameAlter peopleNameAlterDelete = (PeopleNameAlter) treeMap
							.get(string);
					deletePeople(peopleNameAlterDelete.id);
					namelingshi = string;
				}
			});
			text.setText(string);
			return v;
		}

		public boolean hasStableIds() {
			return false;
		}

		public boolean isChildSelectable(int groupPosition, int childPosition) {
			return true;
		}

	}

(4)讓ExpandableListView使用適配器

expandablelistview.setAdapter(new ExpandableAdapter());

具體的顯示效果,可以再適配器中進行設置。


網(wǎng)站題目:Android二級列表
路徑分享:http://weahome.cn/article/igijpg.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部