你必须实现这样的类。
public class DetailedTicketSystemView extends LinearLayout
{
static int inc = 100;
ArrayList<XmlScommessaInCorso> _viewData;
ArrayList<xmlSistemaMovimenti> _systems;
Context _context;
public DetailedTicketSystemView(Context context, int res, AttributeSet attrs, ArrayList<XmlScommessaInCorso> viewData, ArrayList<xmlSistemaMovimenti> systems)
{
super(context, attrs);
_context = context;
_viewData = viewData;
_systems = systems;
LayoutInflater.from(context).inflate(res, this, true);
setId(inc);
inc++;
setLayout();
}
private void setLayout()
{
TextView textView;
String text;
for (int i = 0; i < _systems.size(); i++)
{
View quotesView = (View) LayoutInflater.from(_context).inflate(R.layout.row_ticket_detail_system_layout, null, true);
quotesView.setId(i);
// System Id
textView = (TextView) quotesView.findViewById(R.id.systemId);
text = "" + _context.getString(R.string.id_sistema) + " " + _systems.get(i).getAttributeOrVoidString(xmlSistemaMovimenti.ATTR_id) +
" / " + _viewData.size();
textView.setText(text);
// System Columns
textView = (TextView) quotesView.findViewById(R.id.systemColumns);
text = "" + _context.getString(R.string.colonne) + " " + _systems.get(i).getAttributeOrVoidString(xmlSistemaMovimenti.ATTR_n_multiple_sis);
textView.setText(text);
// System Bet Text
textView = (TextView) quotesView.findViewById(R.id.systemBetText);
textView.setText(R.string.importoPerColonna);
// System bet Value
textView = (TextView) quotesView.findViewById(R.id.systemBetValue);
text = "€ " + XmlScommessaInCorso.getQuotaFormattedOrVoid(_systems.get(i).getAttributeOrVoidString(xmlSistemaMovimenti.ATTR_impo_sistema));
textView.setText(text);
LinearLayout primaryLayout = (LinearLayout) findViewById(R.id.primaryLayout);
primaryLayout.addView(quotesView);
}
}
}