Thanks for the support!

I'm sorry for not making it clear for you... maybe I wasn't even able
to understand what I was trying to do hehe...
So, you got it right! that's exactly what I need! "get the group
position based on the button that was pressed", but the problem is
that as I'm on my first android project I have no idea what you were
talking about... I mean, I understood but I just didn't know what to
do. The first thing is that I'm not sure how to do that with my
adapter, let me show you my whole class (don't worry it's not big) so
that you can have an idea what this is doing so far:

public class ExpList extends ExpandableListActivity {
        private String TAG = "myTag";

        static final String texto1[][] = { { "Group 1", "test1", },
                        { "Group 2", "test2", },
                        { "Group 3", "test3", },
                        { "Group 4", "test4", },
                        { "Group 5", "test5", }, };

        static final String childTexts[][] = {
                        { "Rua José pinto brandão 95, apt 32B", "São Paulo - SP 
- Brazil",
                                        "55 11 56607209", },
                        { "Rua José pinto brandão 95, apt 32B", "São Paulo - SP 
- Brazil",
                                        "55 11 56607209", },
                        { "Rua José pinto brandão 95, apt 32B", "São Paulo - SP 
- Brazil",
                                        "55 11 56607209", },
                        { "Rua José pinto brandão 95, apt 32B", "São Paulo - SP 
- Brazil",
                                        "55 11 56607209", },
                        { "Rua José pinto brandão 95, apt 32B", "São Paulo - SP 
- Brazil",
                                        "55 11 56607209", } };

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                setContentView(R.layout.main);

                getExpandableListView().setOnGroupClickListener(new
OnGroupClickListener() {
                        @Override
                        public boolean onGroupClick(ExpandableListView parent, 
View v,
                                        final int groupPosition, long id) {

                                String groupNameExpanded = 
texto1[groupPosition][0];
                                Log.i(TAG, "expanded: " + groupNameExpanded);

                                return false;
                        }
                });

                getExpandableListView().setOnChildClickListener(new
OnChildClickListener() {

                        @Override
                        public boolean onChildClick(ExpandableListView parent, 
View v,
                                        int groupPosition, int childPosition, 
long id) {

                                // when the user hits the child I want the 
group to collapse as
well
                                
getExpandableListView().collapseGroup(groupPosition);

                                return false;
                        }
                });

                SimpleExpandableListAdapter expListAdapter = new
SimpleExpandableListAdapter(
                                this,
                                // groupData describes the first-level entries
                                createGroupList(),
                                // Layout for the first-level entries
                                R.layout.group_row,
                                // Key in the groupData maps to display
                                new String[] { "texto1", "phone" },
                                // Data under "texto1" key goes into this 
TextView
                                new int[] { R.id.texto1 },
                                // childData describes second-level entries
                                createChildList(),
                                // Layout for second-level entries
                                R.layout.child_row,
                                // Keys in childData maps to display
                                new String[] { "texto2_1", "texto2_2", "phone2" 
},
                                // Data under the keys above go into these 
TextViews
                                new int[] { R.id.texto2_1, R.id.texto2_2, 
R.id.phone2 });

                // remove the indicator
                getExpandableListView().setGroupIndicator(null);
                setListAdapter(expListAdapter);
        }



        @Override
        public void onGroupExpand(int groupPosition) {
                super.onGroupExpand(groupPosition);

                String groupNameExpanded = texto1[groupPosition][0];
                Log.i(TAG, "expanded: " + groupNameExpanded);

                final int GROUP_SIZE = texto1.length;
                for (int i = 0; i < GROUP_SIZE; ++i) {
                        if (i == groupPosition) {
                                continue;
                        } else if (getExpandableListView().isGroupExpanded(i)) {
                                // if the group is already expanded, collapse it
                                getExpandableListView().collapseGroup(i);
                        }
                }
        }

        /**
         * Creates the group list out of the texto1[] array according to the
         * structure required by SimpleExpandableListAdapter. The resulting
List
         * contains Maps. Each Map contains one entry with key "texto1" and
value of
         * an entry in the colors[] array.
         */
        private List<HashMap<String, String>> createGroupList() {
                ArrayList<HashMap<String, String>> result = new
ArrayList<HashMap<String, String>>();

                for (int i = 0; i < texto1.length; ++i) {

                        final int NUMBER_OF_DIMENSIONS = 2;
                        for (int n = 0; n < texto1[i].length; n += 
NUMBER_OF_DIMENSIONS) {
                                HashMap<String, String> child = new 
HashMap<String, String>();

                                child.put("texto1", texto1[i][n]);
                                child.put("phone", texto1[i][n + 1]);
                                result.add(child);
                        }
                }
                return result;
        }

        /**
         * Creates the child list out of the childTexts[] array according to
the
         * structure required by SimpleExpandableListAdapter. The resulting
List
         * contains one list for each group. Each such second-level group
contains
         * Maps. Each such Map contains two keys: "shadeName" is the name of
the
         * shade and "phone" is the PHONE value for the shade.
         */
        private List<ArrayList<HashMap<String, String>>> createChildList() {
                ArrayList<ArrayList<HashMap<String, String>>> result = new
ArrayList<ArrayList<HashMap<String, String>>>();
                for (int i = 0; i < childTexts.length; ++i) {
                        // Second-level lists
                        ArrayList<HashMap<String, String>> secList = new
ArrayList<HashMap<String, String>>();
                        final int NUMBER_OF_DIMENSIONS = 3;
                        for (int n = 0; n < childTexts[i].length; n +=
NUMBER_OF_DIMENSIONS) {
                                HashMap<String, String> child = new 
HashMap<String, String>();

                                child.put("texto2_1", childTexts[i][n]);
                                child.put("texto2_2", childTexts[i][n + 1]);
                                child.put("phone2", childTexts[i][n + 2]);
                                secList.add(child);
                        }
                        result.add(secList);
                }
                return result;
        }

}

So where exactly should I get the parent of the button and how would I
get the view's index in the adapter? I'm not sure how Tag works.. I'll
take a look at some samples in the meanwhile...

On Feb 5, 1:09 pm, TreKing <[email protected]> wrote:
> On Fri, Feb 5, 2010 at 8:39 AM, Gustavo <[email protected]> wrote:
> > you told me "setOnGroupClickListener" because I can get the
> > groupPosition and that's exactly what I need BUT it only works after I
> > click on the group since it's inside setOnGroupClickListener where can
> > I place the button's onClickListener so that I can get the
> > groupPosition?
>
> I'm not really sure what you're asking. If you're trying to get the group
> position based on the button that was pressed, I guess you could try:
> a ) Get the parent of the button which would be the group and get that
> view's index in the adapter.
> b) Store the group index in the each button's Tag property
> c) Store a map of Buttons -> group index that you can index.
>
> If this is not what you mean you'll have to clarify.
>
> --------------------------------------------------------------------------- 
> ----------------------
> TreKing - Chicago transit tracking app for Android-powered 
> deviceshttp://sites.google.com/site/rezmobileapps/treking

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to