This is my first question, I need to add dynamically textViews
to convertView
that is returned in getChildView()
method expandable, but I can not do in any way..
@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;
}
But I can not add the textView
to convertView
. The application always returns unexpected behaviour.