ExpandedListView项目上的致命错误单击Mono for Android

时间:2012-11-20 15:34:50

标签: c# android mono expandablelistview

我有一个内置Mono for Android的Android应用程序,我有一个ExpandableListView。 我正在为我的列表适配器扩展BaseExpandableListAdapter类。

这是我活动的OnCreate方法:

protected override void OnCreate(Bundle savedInstanceState) 
{        
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
lv = (ExpandableListView)FindViewById(Resource.Id.lv);
var expandableAdapter = new MyExpandableListAdapter(this);
lv.SetAdapter(expandableAdapter);
}

列表已正确加载,但是当我点击某个项目时,我会遇到致命的异常。 我运行调试,并在执行GetChildView方法后发生异常。

public override View GetChildView(int groupPosition, int childPosition, bool isLastChild,View convertView, ViewGroup parent) 
{
if (convertView == null)
{
LayoutInflater infaInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
convertView = infaInflater.Inflate(Resource.Layout.childLayout, null);
}

TextView textView = (TextView)convertView.FindViewById(Resource.Id.tvChild);
textView.SetText(GetChild(groupPosition, childPosition).ToString(), TextView.BufferType.Normal);
return textView;
}

这是异常消息:

FATAL EXCEPTION: main
E/AndroidRuntime(12474): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams 
:at android.widget.ListView.setupChild(ListView.java:1806)
:at android.widget.ListView.makeAndAddView(ListView.java:1775)
:at android.widget.ListView.fillDown(ListView.java:672)

0 个答案:

没有答案