Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 具有可扩展细节的xml解析_Android_Xml Parsing_Expandablelistview - Fatal编程技术网

Android 具有可扩展细节的xml解析

Android 具有可扩展细节的xml解析,android,xml-parsing,expandablelistview,Android,Xml Parsing,Expandablelistview,嗨,我有一个xml解析示例。在这里我必须添加可扩展的listview。如何在这里添加。请帮助我 check the below code snippet: ListView lv; lv = (ListView) findViewById(R.id.ListView01); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { public void onItem

嗨,我有一个xml解析示例。在这里我必须添加可扩展的listview。如何在这里添加。请帮助我

check the below code snippet:
ListView lv;
lv = (ListView) findViewById(R.id.ListView01);
lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
gotoActivity();

            }
        });

start your activity in gotoactivity method using startActivityforResult method to take the values 
这是我的代码:

public class SingleMenuItemActivity extends ExpandableListActivity {
static final String KEY_ARTIST = "payment_method";
static final String KEY_SUBTOTAL = "subtotal";
static final String KEY_DISCOUNT = "discount";

@SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
    try{
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         Intent in = getIntent();
         String subtotal = in.getStringExtra(KEY_SUBTOTAL);
         String discount = in.getStringExtra(KEY_DISCOUNT);
         String payment_method = in.getStringExtra(KEY_ARTIST);

         TextView lblSub = (TextView) findViewById(R.id.subtotal_label);
         TextView lblTotal = (TextView) findViewById(R.id.total_label);
         TextView lblPayment = (TextView) findViewById(R.id.payment_label);

         lblSub.setText(subtotal);
         lbldiscount.setText(discount);
         lblPayment.setText(payment_method);

    SimpleExpandableListAdapter expListAdapter =
        new SimpleExpandableListAdapter(
                this,
                createGroupList(),              // Creating group List.
                R.layout.group_row,             // Group item layout XML.
                new String[] { "Order Info" },  // the key of group item.
                new int[] { R.id.order},

                // ID of each group item.-Data under the key goes into this TextView.
                createChildList(),              // childData describes second-level entries.
                R.layout.single_list_item,             // Layout for sub-level entries(second level).
                new String[] {"payment_label:"},      // Keys in childData maps to display.
                new int[] { R.id.payment_label}     // Data under the keys above go into these TextViews.
            );
        setListAdapter( expListAdapter );       // setting the adapter in the list.

    }catch(Exception e){
        System.out.println("Errrr +++ " + e.getMessage());
    }
}

/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
      ArrayList result = new ArrayList();
      for( int i = 0 ; i < 1 ; ++i ) { // 15 groups........
        HashMap m = new HashMap();
        m.put( "Order Info","Order Info " + i ); // the key and it's value.
        result.add( m );
      }
      return (List)result;

}

/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList() {

    ArrayList result = new ArrayList();
    for( int i = 0 ; i < 2 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
      /* each group need each HashMap-Here for each group we have 3 subgroups */
      ArrayList secList = new ArrayList();
      for( int n = 0 ; n < 1 ; n++ ) {
        HashMap child = new HashMap();
        child.put( "payment_label", "payment_label " + n );

        secList.add( child );
      }
     result.add( secList );
    }
    return result;
}
public void  onContentChanged  () {
    System.out.println("onContentChanged");
    super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
    System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
    return true;
}

/* This function is called on expansion of the group */
public void  onGroupExpand  (int groupPosition) {
    try{
         System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
    }catch(Exception e){
        System.out.println(" groupPosition Errrr +++ " + e.getMessage());
    }
}
公共类SingleMenuItemActivity扩展了ExpandableListActivity{
静态最终字符串键\u ARTIST=“付款方法”;
静态最终字符串键\u SUBTOTAL=“SUBTOTAL”;
静态最终字符串键\u折扣=“折扣”;
@抑制警告(“未选中”)
创建时的公共void(Bundle savedInstanceState){
试一试{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent in=getIntent();
字符串小计=in.getStringExtra(关键字小计);
字符串折扣=in.getStringExtra(关键字折扣);
字符串付款方法=in.getStringExtra(关键字);
TextView lblSub=(TextView)findViewById(R.id.subtotal_标签);
TextView lblTotal=(TextView)findViewById(R.id.total_标签);
TextView lblPayment=(TextView)findViewById(R.id.payment_标签);
lblSub.setText(小计);
lbldiscont.setText(折扣);
lblPayment.setText(付款方式);
SimpleExpandableListAdapter解释适配器=
新的SimpleExpandableListAdapter(
这
createGroupList(),//正在创建组列表。
R.layout.group_行,//组项布局XML。
新字符串[]{“订单信息”},//组项的键。
新的int[]{R.id.order},
//每个组项的ID。-键下的数据进入此文本视图。
createChildList(),//childData描述二级条目。
R.layout.single_list_项,//子级条目的布局(第二级)。
新字符串[]{“payment_label:”},//要显示的childData映射中的键。
新的int[]{R.id.payment_label}//上述键下的数据进入这些文本视图。
);
setListAdapter(expListAdapter);//在列表中设置适配器。
}捕获(例外e){
System.out.println(“Errrr++”+e.getMessage());
}
}
/*为行创建Hashmap*/
@抑制警告(“未选中”)
私有列表createGroupList(){
ArrayList结果=新建ArrayList();
对于(int i=0;i<1;++i){//15组。。。。。。。。
HashMap m=新的HashMap();
m、 put(“Order Info”,“Order Info”+i);//键及其值。
结果:添加(m);
}
返回(列表)结果;
}
/*为孩子们创建HashMap*/
@抑制警告(“未选中”)
私有列表createChildList(){
ArrayList结果=新建ArrayList();
对于(inti=0;i<2;++i){//这-15是组数(这里是15)
/*每个组都需要每个HashMap。对于每个组,我们有3个子组*/
ArrayList secList=新的ArrayList();
对于(int n=0;n<1;n++){
HashMap child=新的HashMap();
child.put(“付款标签”、“付款标签”+n);
secList.add(子项);
}
结果。添加(secList);
}
返回结果;
}
内容更改时的公共无效(){
System.out.println(“onContentChanged”);
super.onContentChanged();
}
/*每次单击子项时都会调用此函数*/
公共布尔onChildClick(ExpandableListView父视图、视图v、int-groupPosition、int-childPosition、长id){
System.out.println(“在groupPosition=“+groupPosition+”子对象在位置“+childPosition”处单击的内部onChildClick”);
返回true;
}
/*此函数在组扩展时调用*/
public void onGroupExpand(int groupPosition){
试一试{
System.out.println(“组扩展侦听器=>groupPosition=“+groupPosition”);
}捕获(例外e){
System.out.println(“grouppositionerrrr++”+e.getMessage());
}
}
}
如果我必须单击特定产品,则表示它进入下一个活动。下一个活动具有带有可展开按钮的详细说明。如果我必须单击详细说明,则表示它已展开并显示付款方式、小计、,折扣,否则它是留在少。请帮助我。如何做…如何开发我的代码与上述应用程序

我的main.xml文件是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
  <ExpandableListView android:id="@+id/android:list"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:background="@drawable/bkg"/>

 <TextView android:id="@+id/android:empty"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:text="No items"/>

这里我得到的输出是零…我可以在这里做什么更改。请帮助我。

检查下面的代码片段:
check the below code snippet:
ListView lv;
lv = (ListView) findViewById(R.id.ListView01);
lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
gotoActivity();

            }
        });

start your activity in gotoactivity method using startActivityforResult method to take the values 
ListView lv; lv=(ListView)findViewById(R.id.ListView01); 低压设置适配器(适配器); lv.setOnItemClickListener(新的OnItemClickListener(){ public void onItemClick(AdapterView父级、视图、, 内部位置,长id){ gotoActivity(); } }); 在gotoactivity方法中启动活动,使用startActivityforResult方法获取值
如果我必须单击详细描述,则表示它已展开并显示标题、艺术家、持续时间,否则它将变短。否则它将停留在较短的时间内。请帮助我。如何操作…我已完成此示例中的可展开列表视图:在xml解析代码中如何操作