嗨,我有一个 xml 解析示例。在这里我必须添加可扩展的列表视图。如何在此处添加。请帮助我。
这是我的代码:
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());
}
}
如果我必须点击特定产品意味着它是去下一个活动。下一个活动有详细的描述和可扩展按钮。如果我必须点击详细描述意味着它被展开并显示 payment_method,subtotal,discount 否则它会留在less.please help me.how is to do....如何使用上述应用程序开发我的代码。
我的 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"/>
在这里我得到的输出为零......我可以在这里做些什么改变。请帮助我。