2017-03-01 7 views
0

子ビューでボタンをクリックしてtxtChild.Text = "some Words...";ボタンをクリックした後、アンドロイドでExpandable List Viewを表示します。 私は子供の位置をクリックして、最後の子供だけを変更したいですか? どうすればよいですか?edit TextView子ビューでExpandableListView android

これは私のExpandableListAdapterクラス

` クラスExpandableListAdapterです:BaseExpandableListAdapter { のTextView txtListChild。

private Activity _context; 

    private List<string> _listDataHeader; // header titles 

    // child data in format of header title, child title 

    private Dictionary<string, List<string>> _listDataChild; 





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


    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); 
     if (convertView == null) 
     { 
      convertView = _context.LayoutInflater.Inflate(Resource.Layout.ListItemCustomLayout, null); 
      txtListChild = (TextView)convertView.FindViewById(Resource.Id.lListItem); 
       Button CollectAll = (Button)convertView.FindViewById(Resource.Id.button1); 

       CollectAll.Click += delegate 
       { 
        txtListChild.Text = "some words .."; 
       // i want child position clicked only text changed 

       }; 
     } 


     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.lListHeader); 
     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; 
    } 

}` 

と、この私の活動

public class layout1 : Activity 
{ 
    Sqlitedb db = new Sqlitedb(); 
    ExpandableListAdapter listAdapter; 
    ExpandableListView expListView; 

    List<string> listDataHeader; 
    Dictionary<string, List<string>> listDataChild; 
    int previousGroup = -1; 

     protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     SetContentView(Resource.Layout.layout1); 

     // Create your application here 
     expListView = FindViewById<ExpandableListView>(Resource.Id.vExp); 

     //// Prepare list data 
     prepareListData(); 

     //Bind list 
     listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); 
     expListView.SetAdapter(listAdapter); 

     FnClickEvents(); 




    } 



     void prepareListData() 
     { 
      listDataHeader = new List<String>(); 
      listDataChild = new Dictionary<String, List<String>>(); 

      // Adding child data 
      listDataHeader.Add("Top 250"); 
      listDataHeader.Add("Now Showing"); 
      listDataHeader.Add("Coming Soon.."); 

      // Adding child data 
      List<String> top250 = new List<String>(); 
      top250.Add("The Shawshank Redemption"); 
      top250.Add("The Godfather"); 
      top250.Add("The Godfather: Part II"); 
      top250.Add("Pulp Fiction"); 
      top250.Add("The Good, the Bad and the Ugly"); 
      top250.Add("The Dark Knight"); 
      top250.Add("12 Angry Men"); 

      List<String> nowShowing = new List<String>(); 
      nowShowing.Add("The Conjuring"); 
      nowShowing.Add("Despicable Me 2"); 
      nowShowing.Add("Turbo"); 
      nowShowing.Add("Grown Ups 2"); 
      nowShowing.Add("Red 2"); 
      nowShowing.Add("The Wolverine"); 

      List<String> comingSoon = new List<String>(); 
      comingSoon.Add("2 Guns"); 
      comingSoon.Add("The Smurfs 2"); 
      comingSoon.Add("The Spectacular Now"); 
      comingSoon.Add("The Canyons"); 
      comingSoon.Add("Europa Report"); 

      // Header, Child data 


      listDataChild.Add(listDataHeader[0], top250); 
      listDataChild.Add(listDataHeader[1], nowShowing); 
      listDataChild.Add(listDataHeader[2], comingSoon); 
      //RunOnUiThread(() => 
      //{ 
      // listDataChild.Remove("Top 250"); 
      // listAdapter.NotifyDataSetChanged(); 


      //}); 

     } 







     void FnClickEvents() 
    { 
     //Listening to child item selection 
     expListView.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e) 
     { 

      // listDataChild.Visibility = Android.Views.ViewStates.Gone; 
      Toast.MakeText(this, "child", ToastLength.Short).Show(); 
     }; 

     //Listening to group expand 
     //modified so that on selection of one group other opened group has been closed 
     expListView.GroupExpand += delegate(object sender, ExpandableListView.GroupExpandEventArgs e) 
     { 

      if (e.GroupPosition != previousGroup) 
       expListView.CollapseGroup(previousGroup); 
      previousGroup = e.GroupPosition; 
     }; 

     //Listening to group collapse 
     expListView.GroupCollapse += delegate(object sender, ExpandableListView.GroupCollapseEventArgs e) 
     { 
      Toast.MakeText(this, "group", ToastLength.Short).Show(); 
     }; 
    } 



} 
+0

を私たちは、あなたがそれを修正することができますように、あなたのコードを投稿してください。 –

+0

私はそれを助けてください助けてください – Esraa

答えて

0

私のテキストビューtxtChild.Text = "いくつかの単語を..." 変更したときに、私は拡張可能なリストビューのアンドロイドを持っています。同じ子ビューでボタンをクリックした後、最後の子のみがすべての親で編集する!!

あなたは世界的に以下のようなtxtChildを保存するので、それはです:

class ExpandableListAdapter : BaseExpandableListAdapter { 
    TextView txtListChild; 
    ... 
    public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) 
    { 
     ... 
     txtListChild = (TextView)convertView.FindViewById(Resource.Id.lListItem); 
     ... 
    } 
    txtListChild.Text = childText; 
    return convertView; 
} 

だから、子供の景色がレンダリング得るとき。 GetChildViewが複数回呼び出され、最後の子ビューにtxtListChildが示されます。あなたは、単に以下のような方法GetChildView内側に宣言TextView txtListChildを移動する必要がある問題の修正

class ExpandableListAdapter : BaseExpandableListAdapter { 
    ... 
    public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) 
    { 
     TextView txtListChild; 
     ... 
     txtListChild = (TextView)convertView.FindViewById(Resource.Id.lListItem); 
     ... 
     txtListChild.Text = childText; 
    } 
    return convertView; 
} 
+0

それを解決:) :)、非常に助けてくれてありがとう@エルビス夏 - MSFT – Esraa

関連する問題