在expandable listview android中添加动态创建的视图到convertview

时间:2014-04-24 11:43:49

标签: expandablelistadapter convertview

这是我的第一个问题,我需要动态地textViews添加convertView getChildView()方法中的 @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { ViewHolderChild holder; LayoutInflater inflater = context.getLayoutInflater(); if (convertView == null) { convertView = inflater.inflate(R.layout.child_line, null); holder = new ViewHolderChild(); holder.txNumeroSolicitacao = (TextView) convertView.findViewById(R.id.textViewNumeroSolicitacao); convertView.setTag(holder); } else { holder = (ViewHolderChild) convertView.getTag(); } holder.txNumeroSolicitacao.setText(String.valueOf(getChild(groupPosition,childPosition).getNumero())); //if my log list isn't empty, I want add a textview dynamically to view if(!getChild(groupPosition,childPosition).getLog().isEmpty()) { holder.textViewResponse = new TextView(context); RelativeLayout.LayoutParams alignParentLeft = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); alignParentLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); holder.textViewResponse.setLayoutParams(alignParentLeft); ((ViewGroup) convertView).addView(holder.textViewResponse); } return convertView; } 方法可扩展,但我不能以任何方式做..

textView

但我无法将convertView添加到{{1}}。应用程序始终返回意外行为。

1 个答案:

答案 0 :(得分:0)

您可以在child_line.xml中添加带有android:visibility ="去掉#34;的TextView,并根据当前行的绑定对象&#39在getChildView中设置它的可见性。 ; s日志为空。