这是我的第一个问题,我需要动态添加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
. 应用程序总是返回意外行为。