I wrote a custom ExpandableListView which Header is a Relative Layout with a child of TextView and Button.
In GetGroupView I define a btn.Click delegate which starts a new Activity:
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
var view = convertView;
var group = this.groups[groupPosition];
if (view == null)
{
var inflater = context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
view = inflater.Inflate(Resource.Layout.ExpListViewItem, null);
}
view.FindViewById<TextView>(Resource.Id.expListViewItem_txt).Text = group.GetHeader();
view.FindViewById<Button>(Resource.Id.expListViewItem_btn).Focusable = false;
view.FindViewById<Button>(Resource.Id.expListViewItem_btn).Click += (object sender, EventArgs e) =>
{
var type = e.GetType();
if(sender.GetType() == typeof(Button))
{
Intent temp = new Intent(context,typeof(TestActivity));
temp.PutExtra("TestValue", group.GetHeader());
context.StartActivity(typeof(TestActivity));
}
};
return view;
}
If I click on a ChildItem I want to start another Activity:
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
var view = convertView;
var group = this.groups[groupPosition];
var item = group.GetItems()[childPosition];
if (view == null)
{
var inflater = context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
view = inflater.Inflate(Resource.Layout.expListViewChildren, null);
}
view.FindViewById<TextView>(Resource.Id.expListViewChildren_txt).Text = item.GetHeader();
view.Click += delegate
{
Intent temp = new Intent(context, typeof(test));
temp.PutExtra("TestValue", item.GetHeader());
context.StartActivity(temp);
};
return view;
}
If the ListView is collapsed, everything is fine but if its expanded, the Activity starts twice (due to the fact, that the btn.click delegate gets fired twice).
What am I missing here?
Thanks for your help!