我以 XML 表格布局格式制作了座位安排布局,并且我想要设置 URL 中的 XML 数据以在下面的布局中进行设置。
<小时/>我做了如下的布局
<小时/> <小时/>现在需要有关如何将数据填充到每个集合中的逻辑和提示,如下所示
<小时/> 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
最佳答案
如果您知道您拥有的座位的行数和列数,则创建 Seat 对象类型的矩阵[ROWS][COLS]。 座位对象将包含以下数据甲板(int),高度,宽度 当您创建所有用户界面时,您将需要根据从columnNo和rowNo获取的索引来填充数据
关于java - 将在线 XML 数据设置/传递到表格布局中的图像按钮的逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37046145/