有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

用于设置/将数据从联机XML传递到表布局中的图像按钮的java逻辑

我以XML表格布局格式进行了座位安排布局,我希望将URL中的XML数据设置为下面的布局


我做了如下布局


image1


现在需要关于如何将数据填充到每个集合的逻辑和提示,如下所示


    SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL("http://www.xxxxx.com"); // URL of the XML
/**
* Create the Handler to handle each of the XML tags.
**/
XMLHandler myXMLHandler = new XMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
} catch (Exception e) {
System.out.println(e);
}
data = XMLHandler.data;
/**
* Makes the TextView length the size of the TextView arrays by getting the size of the
**/
title = new TextView[data.getTitle().size()];
artist = new TextView[data.getArtist().size()];
country = new TextView[data.getCountry().size()];
company = new TextView[data.getCompany().size()];
price = new TextView[data.getPrice().size()];
year = new TextView[data.getYear().size()];
/**
* Run a for loop to set All the TextViews with text until
* the size of the array is reached.
*
**/
for (int i = 0; i < data.getTitle().size(); i++) {
title[i] = new TextView(this);
title[i].setText("xxxx = "+data.getTitle().get(i));
artist[i] = new TextView(this);
artist[i].setText("xxxx = "+data.getArtist().get(i));
country[i] = new TextView(this);
country[i].setText("Country = "+data.getCountry().get(i));
company[i] = new TextView(this);
company[i].setText("xxxx = "+data.getCompany().get(i));
price[i] = new TextView(this);
price[i].setText("Price = "+data.getPrice().get(i));
year[i] = new TextView(this);
year[i].setText("xxxx = "+data.getYear().get(i));
((ViewGroup) layout).addView(title[i]);
((ViewGroup) layout).addView(artist[i]);
((ViewGroup) layout).addView(country[i]);
((ViewGroup) layout).addView(company[i]);
((ViewGroup) layout).addView(price[i]);
((ViewGroup) layout).addView(year[i]);
}
setContentView(layout);
}
} 

我正在使用此链接click here

enter image description here


共 (1) 个答案

  1. # 1 楼答案

    如果您知道座椅的行和列,请创建座椅对象类型的矩阵[ROWS][COLS]。 座椅对象将包含以下数据组(int)、高度、宽度 创建所有ui时,需要根据从columnNo和rowNo获得的索引填充数据