有几个问题可以解决这个问题,但没有一个问题对我有用。我试图在ExpandableListView的父单元格之间添加大约10 dp的空间,但不在子单元格之间添加。我几乎尝试了一切。问题是我需要父细胞在未展开时也是圆形的,然后在展开时需要半圆形(只有顶角)。当扩展时,每组中的最后一个孩子是半圆形(相反的方式),因此每个组像整个圆形方块。我已经完成了圆角,但不能在父细胞之间获得空间。
有人可以帮我一个好办法吗?
我目前的尝试:
@Override
public int getGroupCount() {
return (bunches.size()*2)-1;
}
...在getGroupView()中我根据位置设置视图......
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
if (groupPosition%2!=0) {
convertView = mInflater.inflate(R.layout.fakeview, null);
} else {
convertView = mInflater.inflate(R.layout.header_item, null);
convertView.setBackgroundResource(R.drawable.custom_listview_item_header_expanded);
holder.name = (TextView) convertView.findViewById(R.id.expandable_list_title);
holder.numberOfMembers = (TextView)convertView.findViewById(R.id.num_members_textview);
holder.editImageView = (ImageView)convertView.findViewById(R.id.header_item_imageview_edit);
}
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
if (isExpanded) {
convertView.setBackgroundResource(R.drawable.custom_listview_item_expanded);
} else {
convertView.setBackgroundResource(R.drawable.custom_listview_item);
}
...
但是这会在创建单元格时抛出空指针:
11-21 10:00:39.542: E/AndroidRuntime(28855): FATAL EXCEPTION: main
11-21 10:00:39.542: E/AndroidRuntime(28855): Process: me.lunchbunch.stage, PID: 28855
11-21 10:00:39.542: E/AndroidRuntime(28855): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:715)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
11-21 10:00:39.542: E/AndroidRuntime(28855): at me.lunchbunch.core.listadapter.BunchesActivityListAdapter.getGroupView(BunchesActivityListAdapter.java:125)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.AbsListView.obtainView(AbsListView.java:2347)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.ListView.makeAndAddView(ListView.java:1864)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.ListView.fillDown(ListView.java:698)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.ListView.fillFromTop(ListView.java:759)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.ListView.layoutChildren(ListView.java:1673)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.AbsListView.onLayout(AbsListView.java:2151)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.View.layout(View.java:15671)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.ViewGroup.layout(ViewGroup.java:5038)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:581)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.View.layout(View.java:15671)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.view.ViewGroup.layout(ViewGroup.java:5038)
11-21 10:00:39.542: E/AndroidRuntime(28855): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
我的猜测是它抛出一个错误,因为它在一个空的持有者(分隔符)上寻找持有者的属性
答案 0 :(得分:0)
中的NullPointerException
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:715)
可能意味着视图持有者未正确初始化
您正在设置其他内部的持有人。我猜你需要它是什么样的?
if (groupPosition%2!=0) {
convertView = mInflater.inflate(R.layout.fakeview, null);
} else {
convertView = mInflater.inflate(R.layout.header_item, null);
convertView.setBackgroundResource(R.drawable.custom_listview_item_header_expanded);
}
holder.name = (TextView) convertView.findViewById(R.id.expandable_list_title);
holder.numberOfMembers = (TextView)convertView.findViewById(R.id.num_members_textview);
holder.editImageView = (ImageView)convertView.findViewById(R.id.header_item_imageview_edit);