Rewrite public View getGroupView (int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) I return a TextView type variable, why would the following error ah: java.lang.ClassCastException: android.widget.LinearLayout $ LayoutParams cannot be cast to android.widget.AbsListView $ LayoutParams. TextView is a subclass of View, returning subclass no problem in syntax, ah, how it happened to forget everyone pointing.
Reply:
The View is a need to return convertView Okay ......
Reply:
Here you can not directly return textView, application use convertView.
if (convertView == null) {
/ / .......
/ / Your code above
convertView = textView;
else {
if (convertView instanceof TextView) {
((TextView) convertView) setText (group [position]);.
}
}
return convertView; Reply:
API did not say Be sure to return convertView ah, of course, reuse convertView is best, but do not convertView are not right ah.
Reply:
@ Overridestill reported the same nice
public View getGroupView (int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
/ / TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate (R.layout.group, null);
TextView textView = (TextView) layout.findViewById (R.id.group);
textView.setText (group [groupPosition]);
if (convertView == null) {
convertView = textView;
} Else
{
if (convertView instanceof TextView) {
((TextView) convertView) setText (group [groupPosition]);.
}
}
return convertView;
Reply:
You try to change this:
@ Override
public View getGroupView (int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
/ / TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate (R.layout.group, null);
TextView textView = (TextView) layout.findViewById (R.id.group);
textView.setText (group [groupPosition]);
if (convertView == null) {
convertView = textView;
} Else
{
if (convertView instanceof TextView) {
((TextView) convertView) setText (group [groupPosition]);.
}
}
return convertView;
Note the error message
Reply:
The first paste the code are not familiar with, is to change this one:
convertView = inflater.inflate (R.layout.group, null);
Reply:
Such a change is right, I do not understand is that returns a View object right, then I return a TextView object Why wrong? Want to assign the parent child object Is there anything wrong with
Reply:
I think the problem is that you did not initialize convertView, this time you try to change the return Textview object to try to see if he has no error slightly, I think it is getView method is automatically called convertView to fill, so the way to return convertView object
Reply:
Your view should be returned to the parent view addView above, and your textview already has a parent view, I think it is reported iew has parent ... wrong
No comments:
Post a Comment