第一次寫文章,一方面為了分享下自己項(xiàng)目中遇到的一些常見問題,記錄下來方便以后回頭看看,另一方面也是想看下大家有沒有更好的解決方法。寫得不好的地方,還請(qǐng)大家見諒。
1、設(shè)置列表默認(rèn)展開
對(duì)于這個(gè)功能,之前在網(wǎng)上查了好久,最后整理出2寫法。
在class中實(shí)現(xiàn)
for (int i = 0; i < groupCount; i++) {
view.expandGroup(i);
}
在適配器中實(shí)現(xiàn)
@Override
publicView getGroupView(intgroupPosition,booleanisExpanded, View convertView, ViewGroup parent) {
GroupViewHolder viewHolder =null;
if(convertView ==null) {
viewHolder =newGroupViewHolder();
convertView =LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_myorder_head,null);
viewHolder.adapter_myorder_id= (TextView) convertView.findViewById(R.id.adapter_myorder_id);
viewHolder.adapter_myorder_type= (TextView) convertView.findViewById(R.id.adapter_myorder_type);
convertView.setTag(viewHolder);
}else
viewHolder = (GroupViewHolder) convertView.getTag();
viewHolder.adapter_myorder_id.setText(myOrderModel.get(groupPosition).getOrderid());
viewHolder.adapter_myorder_type.setText(Constant.getOrderType(myOrderModel.get(groupPosition).getStatus()));
ExpandableListView expandableListView = (ExpandableListView) parent;
expandableListView.collapseGroup(groupPosition);//先關(guān)閉
expandableListView.expandGroup(groupPosition);//再展開
returnconvertView;
2、實(shí)現(xiàn)groupview不可點(diǎn)擊
網(wǎng)上大多數(shù)方法是setOnGroupClickListener,return true表示不可點(diǎn)擊,不過這不是我要的效果,因?yàn)辄c(diǎn)擊之后,依舊會(huì)有點(diǎn)擊效果,及獲取焦點(diǎn)的現(xiàn)象,感覺怪怪的。我試過給布局中的控件setFocusable為false,不過還是不行。后來無意中發(fā)現(xiàn)一種解決方法,只需要布局中加一層LinearLayout或其他控件,使他覆蓋groupview(如果留了邊距,會(huì)發(fā)現(xiàn)點(diǎn)擊后,空出部分有點(diǎn)擊效果),并設(shè)置background,就可以解決,不過這是治標(biāo)不治本的方法,真正讓groupview不獲取焦點(diǎn),還得以后研究一下。。
3、隱藏自帶的箭頭
只需要view.setGroupIndicator(null)即可實(shí)現(xiàn),也可以用這個(gè)方法設(shè)置自己的圖標(biāo)。