我正在尝试制作每个组的最后一个孩子并编辑文本和按钮。我正在使用自定义ExpandableListViewAdapter。这是我到目前为止所做的。
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
convertView = inflater.Inflate(Resource.Layout.Children, null);
}
if (isLastChild==true)
{
EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
Button button = convertView.FindViewById<Button>(Resource.Id.Button);
TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
textViewItem.Visibility = ViewStates.Gone;
}
else {
TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
Button button = convertView.FindViewById<Button>(Resource.Id.Button);
button.Visibility = ViewStates.Gone;
Submit.Visibility = ViewStates.Gone;
string content = (string)GetChild(groupPosition, childPosition);
textViewItem.Text = content;
}
return convertView;
}
这有助于放置EditText和Button,但仅限于第一组,同时还会切断第一组中的一些子项。
答案 0 :(得分:1)
这有助于放置EditText和Button,但仅限于第一组,同时还会切断第一组中的一些子项。
ExpandableListView
重复使用子视图,因此如果您希望最后一行是您的按钮和edittext,则需要将其设置为显式可见。只需在GetChildView
方法中添加三行代码:
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
convertView = inflater.Inflate(Resource.Layout.Children, null);
}
if (isLastChild == true)
{
EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
Button button = convertView.FindViewById<Button>(Resource.Id.Button);
//add below two lines to your codes
Submit.Visibility = ViewStates.Visible;
button.Visibility = ViewStates.Visible;
TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
textViewItem.Visibility = ViewStates.Gone;
}
else
{
TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
Button button = convertView.FindViewById<Button>(Resource.Id.Button);
button.Visibility = ViewStates.Gone;
Submit.Visibility = ViewStates.Gone;
//also add below line of codes
textViewItem.Visibility = ViewStates.Visible;
string content = (string)GetChild(groupPosition, childPosition);
textViewItem.Text = content;
}
return convertView;
}