Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:21:36+00:00 2026-06-09T12:21:36+00:00

i have developed one xml parsing exmaple.here i have to use expandable listview.but i

  • 0

i have developed one xml parsing exmaple.here i have to use expandable listview.but i can’t do develop this.please help me hoe is to do.

This is code:

 public class CustomExpandableListExampleActivity extends ExpandableListActivity {

ExpandableListAdapter mAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up our adapter
    mAdapter = new MyExpandableListAdapter();
    setListAdapter(mAdapter);
    registerForContextMenu(getExpandableListView());
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    menu.setHeaderTitle("Sample menu");
    menu.add(0, 0, 0, "Sample action");
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

    String title = ((TextView) info.targetView).getText().toString();

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
        Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
                Toast.LENGTH_SHORT).show();
        return true;
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
        return true;
    }

    return false;
}

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
    // Sample data set.  children[i] contains the children (String[]) for groups[i].
    private String[] groups = { "Order Info", "Customer Info" };
    private String[][] children = {
            { "abc", "xyz", "ash", "anu" },
            { "SSE", "TJ", "PM", "SE" },

    };

    public Object getChild(int groupPosition, int childPosition) {
        return children[groupPosition][childPosition];
    }

    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    public int getChildrenCount(int groupPosition) {
        return children[groupPosition].length;
    }

    public TextView getGenericView() {
        // Layout parameters for the ExpandableListView
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, 64);

        TextView textView = new TextView(CustomExpandableListExampleActivity.this);
        textView.setLayoutParams(lp);
        // Center the text vertically
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        // Set the text starting position
        textView.setPadding(36, 0, 0, 0);
        return textView;
    }

    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
            View convertView, ViewGroup parent) {
        TextView textView = getGenericView();
        textView.setText(getChild(groupPosition, childPosition).toString());
        return textView;
    }

    public Object getGroup(int groupPosition) {
        return groups[groupPosition];
    }

    public int getGroupCount() {
        return groups.length;
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
            ViewGroup parent) {
        TextView textView = getGenericView();
        textView.setText(getGroup(groupPosition).toString());
        return textView;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public boolean hasStableIds() {
        return true;
    }

  }
 }

Here the above code have children (abc, xyz, ash, anu) items on orderinfomation.but if i click orderinfo means it is expanded and wish to display this singlemenuitem values(payment_method,subtotal,discount).how is to do.please help me.

public class SingleMenuItemActivity  extends Activity {

// XML node keys
static final String KEY_ARTIST = "payment_method";
static final String KEY_SUBTOTAL = "subtotal";
static final String KEY_DISCOUNT = "discount";
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_list_item);

    // getting intent data
    Intent in = getIntent();

    // Get XML values from previous intent
    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 lblPayment = (TextView) findViewById(R.id.payment_label);
    TextView lbldiscount = (TextView) findViewById(R.id.discount_label);
    lblSub.setText(subtotal);
    lbldiscount.setText(discount);
    lblPayment.setText(payment_method);
     }
       } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:21:38+00:00Added an answer on June 9, 2026 at 12:21 pm

    Here you go with create xml file with ExpandableListView and get the referece on you activity.Create an adapter like below.From activity you set your items as follows

               Map<String, List<CommonTask>> map = new HashMap<String, List<CommonTask>>();
    
        List<CommonTask> childItem1 = new ArrayList<CommonTask>();
        childItem1.add(new CommonTask("Child 1"));
    
    
        List<CommonTask> childItem2 = new ArrayList<CommonTask>();
             childItem2.add(new CommonTask("Child 2"));
    
                map.put("Parent 1", childItem1);
        map.put("Parent 2", childItem2);
    
              // Set on listview ExpandableListView reference
    
               expandListView.setAdapter(adapter);
    

    public class ExpandableListViewAdapter extends BaseExpandableListAdapter {

    private static final class ViewHolder {
        TextView textLabel;
        TextView groupTextLabel;
    
    }
    
    private final Map.Entry<Object, List<Object>> entries[];
    
    private final LayoutInflater inflater;
    
    
    public ExpandableListViewAdapter(final Context theContext,
            final Map<String, List<CommonTask>> map) {
        inflater = LayoutInflater.from(theContext);
    
        entries = map.entrySet().toArray(new Map.Entry[0]);
    
    }
    
    @Override
    public Object getChild(final int groupPosition, final int childPosition) {
        final List<Object> childList = entries[groupPosition].getValue();
    
        return childList.get(childPosition);
    }
    
    @Override
    public long getChildId(final int groupPosition, final int childPosition) {
        return childPosition;
    }
    
    @Override
    public int getChildrenCount(final int groupPosition) {
    
        final List<Object> childList = entries[groupPosition].getValue();
    
        final int childCount = childList.size();
    
        return childCount;
    }
    
    @Override
    public View getChildView(final int groupPosition, final int childPosition,
            final boolean isLastChild, final View theConvertView,
            final ViewGroup parent) {
        View resultView = theConvertView;
    
        ViewHolder holder = null;
    
        if (resultView == null) {
            resultView = inflater.inflate(R.layout.child_layout, null);
    
            holder = new ViewHolder();
    
            holder.textLabel = (TextView) resultView.findViewById(R.id.title);
    
            resultView.setTag(holder);
        } else {
            holder = (ViewHolder) resultView.getTag();
        }
    
        final Object item = getChild(groupPosition, childPosition);
        CommonTask commonTask = (CommonTask) item;
        holder.textLabel.setText(commonTask.getName());
    
        return resultView;
    }
    
    @Override
    public Object getGroup(final int groupPosition) {
        return entries[groupPosition].getKey();
    }
    
    @Override
    public int getGroupCount() {
        final int groupCount = entries.length;
    
        return groupCount;
    }
    
    @Override
    public long getGroupId(final int groupPosition) {
        return groupPosition;
    }
    
    @Override
    public View getGroupView(final int groupPosition, final boolean isExpanded,
            final View theConvertView, final ViewGroup parent) {
        View resultView = theConvertView;
    
        ViewHolder holder = null;
    
        if (resultView == null) {
            resultView = inflater.inflate(R.layout.group_layout, null);
    
            holder = new ViewHolder();
            holder.groupTextLabel = (TextView) resultView
                    .findViewById(R.id.tvGroup);
    
            resultView.setTag(holder);
        } else {
            holder = (ViewHolder) resultView.getTag();
        }
    
        final Object item = getGroup(groupPosition);
    
        holder.groupTextLabel.setText(item.toString());
    
        return resultView;
    }
    
    @Override
    public boolean hasStableIds() {
        return true;
    }
    
    @Override
    public boolean isChildSelectable(final int groupPosition,
            final int childPosition) {
        return true;
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One business jar which have been developed by us is present in war. but
in my project i have one registration form which is developed in C#.net.to this
Here I have developed one app. Here I wish to need the o/p like
Hi i have to developed one sample app.Here i wish to select the app
I have developed an application which can create Xml files from Xml schema with
I have to developed one expandablelistview.here if i have to run the program means
Hi i have to developed one sample app.Here i wish to select the app
We are a lead generating company and have developed one application where our customers
i have developed our company site where we show one product detail means one
I had developed one website purely in HTML .I have my form with fields

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.