Android XML Pull Parser子节点问题

发布于 2024-11-09 00:15:54 字数 2428 浏览 5 评论 0原文

我的应用程序包括两个活动:

第一个活动将包含从 xml 文件动态创建的一组按钮,当我们单击这些按钮时,第二个活动启动。在第二个活动中,我有可扩展的列表视图,可以根据第一个活动中单击的按钮进行填充。

我的 xml 文件是这样的:

    <classes>
       <class name="3">
      <syllabus name="ICSE " code="ic" id="" >
          <subject name="maths">3 ICSE Maths data</subject>
          <subject name="physics">3 ICSE Physics data</subject>    
          <subject name="chemistry">3 ICSE Chemistry data</subject>
      </syllabus>

      <syllabus name="cbse" code="cb" id="" >
          <subject name="maths">3 CBSE Maths data</subject>
          <subject name="physics">3 CBSE Physics data</subject>    
          <subject name="chemistry">3 CBSE Chemistry data</subject>
      </syllabus>       
   </class>

       <class name="4">
          <syllabus name="ICSE " code="ic" id="" >
              <subject name="maths">4 ICSE Maths data</subject>
              <subject name="physics">4 ICSE Physics data</subject>    
              <subject name="chemistry">4 ICSE Chemistry data</subject>
          </syllabus>

          <syllabus name="cbse" code="cb" id="" >
              <subject name="maths">4 CBSE Maths data</subject>
              <subject name="physics">4 CBSE Physics data</subject>    
              <subject name="chemistry">4 CBSE Chemistry data</subject>
          </syllabus>       
          <syllabus name="ssc" code="ss" id="" >
              <subject name="maths">4 CBSE Maths data</subject>
              <subject name="physics">4 CBSE Physics data</subject>    
              <subject name="chemistry">4 CBSE Chemistry data</subject>
          </syllabus> 
       </class>

     </classes>

在上面的 xml 文件中,类属性名称是我的第一个活动的按钮。就像

类 3

类 4

类 5

类 6

当用户单击特定按钮时,他将被带到另一个具有可扩展列表视图的活动,它看起来像这样:

--> CBSE

   Maths

   Physics

   Science

--> ICSE

   Maths

   Physics

   Science

现在我需要填充这个可扩展列表从 xml 动态列表视图,其中包含 xml 中特定类标记的子节点。 例如,如果用户单击 class3 按钮,则可扩展列表视图必须填充 ICSE 和 CBSE。

如果用户单击 class4 按钮,可扩展列表视图必须从 xml 动态填充 ICSE、CBSE 和 SSC。

请帮助我如何使用示例代码执行此操作。

先感谢您。

My application includes two activities :

1st activity will contain set of buttons created dynamically from the xml file, when we click on these buttons 2nd activity starts. In 2nd activity i have expandable list view to be populated according to the button clicked in 1st activity.

My xml file is like this :

    <classes>
       <class name="3">
      <syllabus name="ICSE " code="ic" id="" >
          <subject name="maths">3 ICSE Maths data</subject>
          <subject name="physics">3 ICSE Physics data</subject>    
          <subject name="chemistry">3 ICSE Chemistry data</subject>
      </syllabus>

      <syllabus name="cbse" code="cb" id="" >
          <subject name="maths">3 CBSE Maths data</subject>
          <subject name="physics">3 CBSE Physics data</subject>    
          <subject name="chemistry">3 CBSE Chemistry data</subject>
      </syllabus>       
   </class>

       <class name="4">
          <syllabus name="ICSE " code="ic" id="" >
              <subject name="maths">4 ICSE Maths data</subject>
              <subject name="physics">4 ICSE Physics data</subject>    
              <subject name="chemistry">4 ICSE Chemistry data</subject>
          </syllabus>

          <syllabus name="cbse" code="cb" id="" >
              <subject name="maths">4 CBSE Maths data</subject>
              <subject name="physics">4 CBSE Physics data</subject>    
              <subject name="chemistry">4 CBSE Chemistry data</subject>
          </syllabus>       
          <syllabus name="ssc" code="ss" id="" >
              <subject name="maths">4 CBSE Maths data</subject>
              <subject name="physics">4 CBSE Physics data</subject>    
              <subject name="chemistry">4 CBSE Chemistry data</subject>
          </syllabus> 
       </class>

     </classes>

In above xml file class attribute name is my button of 1st activity. like

class 3

class 4

class 5

class 6

when the user clicks on particular button he will be taken to another activity with expandable list view, it looks like this:

-->CBSE

   Maths

   Physics

   Science

-->ICSE

   Maths

   Physics

   Science

Now i need to populate this expandable list view dynamically from the xml with the child nodes of particular class tag in xml.
For example if user clicks on class3 button expandable list view has to get populated with ICSE and CBSE.

And if user clicks on class4 button expandable list view has to get populated with ICSE, CBSE and SSC dynamically from xml.

Please help me how to do this with sample code.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文