There are two ways to add different menus for the group and child of expandablelistview:
1. showdialog
This method adds a tag for the view through the adapter and obtains the tag of the view in onitemlongclicklistener of the expandablelistview to determine whether it is group or child. Then, a different menu dialog box is displayed.
CodeAs follows:
-
- @ Override
-
- PublicView getchildview (Final IntArg0,Final IntArg1,BooleanArg2, view,
- Viewgroup arg4 ){
-
- If(View =Null){
-
- View = Inflater. Inflate (R. layout. team_layout_main_list_item,Null);
-
- }
-
- Textview = (textview) view. findviewbyid (R. Id. team_main_list_username );
- Imageview = (imageview) view. findviewbyid (R. Id. team_main_list_head );
-
- Imageview. setimageresource (prortaitutils. conversionidtores (userinfo) getchild (arg0, arg1). getportrait ()));
-
- View. settag (R. Id. team_singlechat_id_send, arg0 );
-
- View. settag (R. Id. team_singlechat_id_close, arg1 );// Note 1
-
- Textview. settext (userinfo) getchild (arg0, arg1). GetUserName ());
- Textview. settextcolor (color. Black );
-
- View. setbackgroundcolor (color. RGB (247,243,247));
-
- View. setbackgroundresource (R. drawable. team_item_bg_selector );
-
- ReturnView;
-
- }
-
- @ Override
- PublicView getgroupview (IntArg0,BooleanArg1, view groupview, viewgroup arg3 ){
-
- If(Groupview =Null){
-
- Groupview = Inflater. Inflate (R. layout. team_layout_main_list_group,Null);
-
- }
- Textview grouptextview = (textview) groupview. findviewbyid (R. Id. team_main_list_teamname );
-
- Imageview groupimageview = (imageview) groupview. findviewbyid (R. Id. team_main_list_into );
-
- Groupimageview. setimageresource (R. drawable. team_1_1 );
-
- If(Arg1 ){
-
- Groupimageview. setimageresource (R. drawable. team_sources 2 );
- }
-
- Groupview. settag (R. Id. team_singlechat_id_send, arg0 );
-
- Groupview. settag (R. Id. team_singlechat_id_close ,-1);// Note 2
-
- Grouptextview. settext (getgroup (arg0). tostring ());
-
- Grouptextview. settextcolor (color. Black );
- ReturnGroupview;
-
- }
-
- // Long-pressed entries, including group and child
-
- Onlinelist. setonitemlongclicklistener (NewOnitemlongclicklistener (){
-
-
- @ Override
- Public BooleanOnitemlongclick (adapterview <?> Arg0,FinalView arg1,
-
- IntArg2,LongArg3 ){
-
- Longclicklistiteam (arg1 );
-
- Return True;
- }
-
- });
-
- /**
-
- * Long press an entry in the list
-
- */
-
- Private VoidLongclicklistiteam (FinalView arg1 ){
- Final IntGrouppos = (integer) arg1.gettag (R. Id. team_singlechat_id_send );
-
- Final IntChildpos = (integer) arg1.gettag (R. Id. team_singlechat_id_close );
-
- Log. I (tag,"Grouppos :"+ Grouppos +", Childpos :"+ Childpos );
- If(Childpos =-1){// If the value of the Child location is-1, the operation group
-
- Log. I (tag,"Operate group components");
-
- Updateteam (arg1 );
-
- }Else{
- Log. I (tag,"Operate child components");// Otherwise, operate child
-
- FinalList <userinfo> Users = getteamuser (grouppos );
-
- // Determine whether the long-pressed button is your own. If it is your own, a dialog box is displayed. If it is your own, view the information.
- If(Dicqconstant. defaultmac. equalsignorecase (users. Get (childpos). getusermac ())){
-
- Intent it =NewIntent (teammainactivity.This, Userinfoactivity.Class);
-
- It. putextra ("Ismyself",True);
- Teammainactivity.This. Startactivity (it );
-
- }Else{
-
- Builder =NewAlertdialog. Builder (teammainactivity.This);
- Builder. settitle ("Operation user");
-
- Builder. setitems (NewString [] {"View materials","View Sharing","Move to group","Permission settings"},NewDialoginterface. onclicklistener (){
- Public VoidOnclick (dialoginterface dialog,IntWhich ){
-
- If(Which =0){
- Intent it =NewIntent (teammainactivity.This, Userinfoactivity.Class);
-
- It. putextra ("Ismyself",False);
- It. putextra ("Userinfo", Users. Get (childpos ));
-
- Teammainactivity.This. Startactivity (it );
- }Else If(Which =1){
-
- Intent it1 =NewIntent (teammainactivity.This, File1_activity.Class);
- It1.putextra ("Userinfo", Users. Get (childpos ));
-
- Teammainactivity.This. Startactivity (it1 );
- }Else If(Which =2){
-
- Updatechild (grouppos, childpos );
- }Else If(Which =3){
-
- Updateuserprivilege (grouppos, childpos );
-
- }
- }
-
- }). Show ();
-
- }
-
-
- }
-
- }
The second method is contextmenu.
In this wayExpandablelistcontextmenuinfo to determine whether it is group or child, and then create different menus
The Code is as follows:
- @ Override
-
- Public void oncreatecontextmenu (contextmenu menu, view V, contextmenuinfo menuinfo ){
-
- Expandablelistview. expandablelistcontextmenuinfo = (expandablelistview. expandablelistcontextmenuinfo) menuinfo;
-
- Int type = expandablelistview. getpackedpositiontype (info. packedposition );
-
- Int group = expandablelistview. getpackedpositiongroup (info. packedposition );
-
- If (type = expandablelistview. packed_position_type_child & group! = 0 ){
-
- Menu. setheadertitle ("sample menu ");
- Menu. Add (0, 0, 0, R. String. expandable_list_sample_action );
-
- }
-
- }