BaseExpandableListAdapter的疑问,该怎么处理
BaseExpandableListAdapter的疑问
public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView,ViewGroup parent)
1.convertView是代表当前显示的样子,那parent是代表什么?
public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent)
2.parent这个具体指什么?
3.组显示的箭头图片是否可以更换?如何更换?
4.
和
效率是否相同?
每题25分
------解决方案--------------------
解释:parent The parent that this view will eventually be attached to
parent是指当前Item所属的view,比如在main.xml里面定义了Expendlistview,那parent就是这个main.xml对应的视图。
(1)getChildView 中parent就是groupview,
(2)getGroupView 中parent就是Expendlistview
(3)http://blog.****.net/timchen6824/article/details/6762996
(4)个人认为getGroupView里有视图缓存,效率高些,
求高人拍砖啊。。。。
------解决方案--------------------
1.是convertView是代表当前显示的样子,那parent是代表组的名称,如QQ群组,如果一个人加入了3个群(群名分别为:“小学同学”,“大学同学”,“同事),各个群下面有好多好友,显示好友的就是convertView,而显示群名称的就是parent
2.parent具体指什么,在1里面已经很明确表示了。
3.当然可以替换,最好是使用替换系统样式的方式,代码如下:
<style name="CustomExpandableListView"
parent="@android:style/Widget.ExpandableListView">
<item name="android:groupIndicator">@drawable/expander_group</item>
</style>
expander_group 定义如下
<style name="CustomExpandableListView"parent="@android:style/Widget.ExpandableListView">
<item name="android:groupIndicator">@drawable/expander_group</item>
</style>
4.效果不一样,一个是修改组名称的背景控件样式,一个是修改成员显示的样式
public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView,ViewGroup parent)
1.convertView是代表当前显示的样子,那parent是代表什么?
public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent)
2.parent这个具体指什么?
3.组显示的箭头图片是否可以更换?如何更换?
4.
- Java code
// 创建组/子视图 public TextView getGenericView(String s) { // Layout parameters for the ExpandableListView AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 40); TextView text = new TextView(a.this); text.setLayoutParams(lp); // Center the text vertically text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); // Set the text starting position text.setPadding(36, 0, 0, 0); text.setText(s); return text; }
和
- Java code
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String string = group.get(groupPosition); LayoutInflater inflater = (LayoutInflater) a.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.c, null); chil c = new chil(); c.tv = (TextView) convertView.findViewById(R.id.tv2); c.tv.setText(string); return convertView; }
效率是否相同?
每题25分
------解决方案--------------------
解释:parent The parent that this view will eventually be attached to
parent是指当前Item所属的view,比如在main.xml里面定义了Expendlistview,那parent就是这个main.xml对应的视图。
(1)getChildView 中parent就是groupview,
(2)getGroupView 中parent就是Expendlistview
(3)http://blog.****.net/timchen6824/article/details/6762996
(4)个人认为getGroupView里有视图缓存,效率高些,
求高人拍砖啊。。。。
------解决方案--------------------
1.是convertView是代表当前显示的样子,那parent是代表组的名称,如QQ群组,如果一个人加入了3个群(群名分别为:“小学同学”,“大学同学”,“同事),各个群下面有好多好友,显示好友的就是convertView,而显示群名称的就是parent
2.parent具体指什么,在1里面已经很明确表示了。
3.当然可以替换,最好是使用替换系统样式的方式,代码如下:
<style name="CustomExpandableListView"
parent="@android:style/Widget.ExpandableListView">
<item name="android:groupIndicator">@drawable/expander_group</item>
</style>
expander_group 定义如下
<style name="CustomExpandableListView"parent="@android:style/Widget.ExpandableListView">
<item name="android:groupIndicator">@drawable/expander_group</item>
</style>
4.效果不一样,一个是修改组名称的背景控件样式,一个是修改成员显示的样式