2017-02-24 1 views
1

하위보기의 단추를 클릭 한 후 그룹에서 하위보기를 제거하는 방법은 무엇입니까?xamarin andriod ExpandableListView : 그룹에서 하위보기 제거 또는 숨기기

class ExpandableListAdapter : BaseExpandableListAdapter { 

    private ListView listview; 
    private LinearLayout mainLayout; 
    private View linearLayout; 

    public Activity _context; 

    TextView txtListChild; 

    private List<string> _listDataHeader; // header titles 
    private Dictionary<string, List<string>> _listDataChild; 

    public ExpandableListAdapter(Activity activity, List<string> listDataHeader, Dictionary<String, List<string>> listChildData) { 
     //, Dictionary<String, List<string>> listChildData2 
     this._context = activity; 
     this._listDataHeader = listDataHeader; 
     this._listDataChild = listChildData; 
     // this._listDataChild2 = listChildData2; 
    } 


    public override Java.Lang.Object GetChild(int groupPosition, int childPosition) { 
     return _listDataChild[_listDataHeader[groupPosition]][childPosition]; 
    } 


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



    public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) { 
     string childText = (string)GetChild(groupPosition, childPosition); 
     convertView = null; 

     if (convertView == null) { 
      convertView = _context.LayoutInflater.Inflate(Resource.Layout.childRowWithButton, null); 

      Button no = (Button)convertView.FindViewById(Resource.Id.gono); 

      no.Click += delegate{ 
       // I want hide my child 
      }; 

      txtListChild.Text = childText; 
     } 
     return convertView; 
    } 

    public override int GetChildrenCount(int groupPosition) { 
     return _listDataChild[_listDataHeader[groupPosition]].Count; 
    } 

    public override Java.Lang.Object GetGroup(int groupPosition) { 
     return _listDataHeader[groupPosition]; 
    } 


    public override long GetGroupId(int groupPosition){ 
     return groupPosition; 
    } 


    public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent){ 
     string headerTitle = (string)GetGroup(groupPosition); 

     convertView = convertView ? ? _context.LayoutInflater.Inflate(Resource.Layout.HeaderCustomLayout, null); 
     var lblListHeader = (TextView)convertView.FindViewById(Resource.Id.Header); 

     //string headerTitle2 = (string)GetGroup(groupPosition); 
     //var ListHeader2 = (TextView)convertView.FindViewById(Resource.Id.Header2); 
     //ListHeader2.Text = headerTitle2; 

     lblListHeader.Text = headerTitle; 

     return convertView; 
    } 


    public override int GroupCount{ 
     get{ 
      return _listDataHeader.Count; 
     } 
    } 


    public override bool HasStableIds{ 
     get{ 
      return false; 
     } 
    } 


    public override bool IsChildSelectable(int groupPosition, int childPosition){ 
     return true; 
    } 
} 

답변

0
당신은 다음 코드로 아이 뷰를 제거 listView.SetOnChildClickListener()을 사용할 수 있습니다

:

public class MainActivity : Activity , IOnChildClickListener 
    { 
     ExpandableListView listView; 
     List<Data> newDataList; 
     ExpandableDataAdapter myadapter; 
     public bool OnChildClick(ExpandableListView parent, View clickedView, int groupPosition, int childPosition, long id) 
     {  
      newDataList.RemoveAt(0); 
      myadapter.NotifyDataSetChanged(); 
      return true; 
     } 

     protected override void OnCreate (Bundle bundle) 
     { 
      base.OnCreate (bundle); 
      SetContentView (Resource.Layout.Main);  
      newDataList = Data.SampleData(); 
      myadapter = new ExpandableDataAdapter(this, newDataList); 
      listView = FindViewById<ExpandableListView> (Resource.Id.myExpandableListview); 
      listView.SetAdapter (myadapter); 
      listView.SetOnChildClickListener(this); 


     } 
    } 

내 샘플에서, 난 그냥 아이의 첫 번째 항목을 제거, 당신은 현재를 얻기 위해 int groupPosition, int childPosition을 사용할 수 있습니다 위치를 클릭하십시오. 그리고 listData에서 제거하십시오. 데이터 세트를 변경할 때 adapter.NotifyDataSetChanged();으로 전화하십시오.

나는 github

스크린 샷에서 ExpandableListView 샘플을 사용하고 있습니다 :

enter image description here

+0

이 근무 ,, 답장을 보내 주셔서 감사합니다 – Esraa

관련 문제