版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34812958/article/details/74207981
public class CNCaseRelationListview extends ListView { private CNCaseRelationAdapter relationAdapter; private String anclsssql = ""; private List<CNCaseRelationModel> modelList; public void setAnId(String anId) { if (anId == null || anId.equals("")) { return; } anclsssql = "select A.id as anId,A.anClass,A.addtime as caseTime from CNANLI as A where isdel = 0 and id='" + anId + "'"; CNCaseRelationModel caseRelationModel = GreenDaoManager.getInstance().queryOne(CNCaseRelationModel.class, anclsssql); caseRelationModel.setViewType(0); modelList.add(caseRelationModel); anclsssql = "select * from CNAnli_Party where isdel = 0 and anId = '" + anId + "'"; List<CNAnliParty> partyArray = GreenDaoManager.getInstance().queryList(CNAnliParty.class, anclsssql); HashMap<String, String> map = new HashMap<>(); for (int i = 0; i < partyArray.size(); i++) { CNAnliParty party = partyArray.get(i); if (map.containsKey(party.getURole())) { map.put(party.getURole(), map.get(party.getURole()) + " " + party.getUName()); } else { map.put(party.getURole(), party.getUName()); } } for (String key : map.keySet()) { CNCaseRelationModel partyModel = new CNCaseRelationModel(); partyModel.setViewType(1); partyModel.setIdentity(key); partyModel.setName(map.get(key)); modelList.add(partyModel); } relationAdapter.replaceDataList(modelList); } public CNCaseRelationListview(Context context) { super(context); } public CNCaseRelationListview(Context context, AttributeSet attrs) { super(context, attrs); modelList = new ArrayList<>(); relationAdapter = new CNCaseRelationAdapter(context); setAdapter(relationAdapter); } public CNCaseRelationListview(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
请注意最后一个方法
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }
固定listview的长度