我正在开发一个 android 应用程序。
我已经传递了 xml 标签。
在这里我遇到了一些问题。请给我一个解决方案。
这些是我的 xml 提要:
<root>
<Categories>
<Category title="books" categoryid="1" image="http://google.com/dsdsds.png" >
<SubCategory>
<Subcategory name="Android" subcategoryid="2" subimage="http://google.comdsdsdsd.jpg" >
<Products>
<product name="android programming" productid="3" >
<Retailers>
<Retailer name='sfsdsds' />
<Retailer name='sdsdsdsd' />
</Retailers>
在这里,我通过零售商使用以下代码:
if (productNode
.hasChildNodes()) {
NodeList retailerNameNL = productElmt
.getElementsByTagName("Retailers");
if (retailerNameNL.getLength() > 0) {
for (int rnCnt = 0; rnCnt < retailerNameNL
.getLength(); rnCnt++) {
Node retailerNameNode = retailerNameNL
.item(rnCnt);
if (retailerNameNode.hasChildNodes()) {
Element retailernamesElmt = (Element) retailerNameNode;
NodeList retailernamesChildNL = retailernamesElmt
.getElementsByTagName("Retailer");
if (retailernamesChildNL.getLength() > 0) {
RetailerNameAL = new ArrayList<RetailerNames>();
for (int rnIdx = 0; rnIdx < retailernamesChildNL
.getLength(); rnIdx++) {
Node retailernamesChildNode = retailernamesChildNL
.item(rnIdx);
RetailerNames retailernamesBean = null;
Element retailernamesChildElmt = null;
if (retailernamesChildNode
.hasAttributes()) {
retailernamesBean = new RetailerNames();
retailernamesChildElmt = (Element) retailernamesChildNode;
retailernamesBean
.setmProductType(retailernamesChildElmt
.getAttribute("name"));
RetailerNameAL
.add(retailernamesBean);
在这里,我得到的零售商名称列表取决于所选的 productid。
我的查询是:
我必须将这些名称列表传递给另一个活动,这取决于productid。
List<String> shoplist = new ArrayList<String>();
shoplist.add(product.getString(TAG_SHOP));
shoplist.addAll(HomePage.retailerNameBean
.getmProductType()
+ ",");
ArrayAdapter<String> shopadapter = new ArrayAdapter<String>(EditWatchListProducts.this,
android.R.layout.simple_spinner_item, shoplist);
但是我正确地获得了第一个项目。之后我得到了该列表中的空项目:
请给我这些解决方案......我怎样才能获得该阵列列表上的零售商名称列表取决于所选类别。