0
我有一個問題要解決,我有三個textviews數組。如何在一個tableLayout中顯示textview數組
- Textview a[];
- TexTview b[];
- TexTview c[]:
我需要在表格中顯示它們,就像這樣:as I need to show it。 但與下面的代碼顯示,畫面是這樣的:so don't need sho like this
((ViewGroup) layout).addView(a[i]);
((ViewGroup)layout).addView(a[i]);
((ViewGroup)layout).addView(a[i]);
這是完整的代碼,提前,非常感謝你。
public class MainActivity extends Activity {
SitesList sitesList = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** Create a new layout to display the view */
View layout = findViewById(R.id.layout);
/** Create a new textview array to display the results */
TextView variacion[];
TextView nemotecnico[];
TextView precio[];
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=75");
/** Create handler to handle XML Tags (extends DefaultHandler) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/** Get result from MyXMLHandler SitlesList Object */
sitesList = MyXMLHandler.sitesList;
/** Assign textview array lenght by arraylist size */
// registro = new TextView[sitesList.getRegistro().size()];
nemotecnico = new TextView[sitesList.getNemotecnico().size()];
variacion = new TextView[sitesList.getVariacion().size()];
precio = new TextView[sitesList.getPrecio().size()];
/** Set the result text in textview and add it to layout */
for (int i = 0; i < sitesList.getRegistro().size(); i++) {
variacion[i] = new TextView(this);
variacion[i].setText(sitesList.getVariacion().get(i));
nemotecnico[i] = new TextView(this);
nemotecnico[i].setText(sitesList.getNemotecnico().get(i));
precio[i] = new TextView(this);
precio[i].setText(sitesList.getPrecio().get(i));
((ViewGroup)layout).addView(nemotecnico[i]);
((ViewGroup)layout).addView(variacion[i]);
((ViewGroup)layout).addView(precio[i]);
}
/** Set the layout view to display */
setContentView(layout);
}
}
多解釋 –