Android二級(jí)列表-創(chuàng)新互聯(lián)

android中二級(jí)列表的顯示與ListView、RecyelerView等步驟類(lèi)似:

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的城步網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

(1)xml布局

<ExpandableListView
        android:id="@+id/expandablelistview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" />

(2)代碼:

private ExpandableListView expandablelistview;// 可擴(kuò)展的二級(jí)列表
//創(chuàng)建對(duì)象
expandablelistview = (ExpandableListView) findViewById(R.id.expandablelistview);
//實(shí)現(xiàn)二級(jí)列表的Group點(diǎn)擊效果
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);// 獲取部門(mén)下的員工信息
					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("無(wú)員工信息");
			}
			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());

具體的顯示效果,可以再適配器中進(jìn)行設(shè)置。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

當(dāng)前題目:Android二級(jí)列表-創(chuàng)新互聯(lián)
本文URL:http://muchs.cn/article20/csjpco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、品牌網(wǎng)站建設(shè)移動(dòng)網(wǎng)站建設(shè)、企業(yè)建站、網(wǎng)站策劃、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作