• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Expandable List Help Needed!

Hey,
I have an expandable list that looks something like..


Code:
public class ExpandableList3 extends ExpandableListActivity {
    private static final String NAME = "NAME";
    private static final String IS_EVEN = "IS_EVEN";
    
    private ExpandableListAdapter mAdapter;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
        List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
        for (int i = 0; i < 20; i++) {
            Map<String, String> curGroupMap = new HashMap<String, String>();
            groupData.add(curGroupMap);
            curGroupMap.put(NAME, "Group " + i);
            curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
            
            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            for (int j = 0; j < 15; j++) {
                Map<String, String> curChildMap = new HashMap<String, String>();
                children.add(curChildMap);
                curChildMap.put(NAME, "Child " + j);
                curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
            }
            childData.add(children);
        }
        
        // Set up our adapter
        mAdapter = new SimpleExpandableListAdapter(
                this,
                groupData,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 },
                childData,
                android.R.layout.simple_expandable_list_item_2,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 }
                );
        setListAdapter(mAdapter);
    }

I want to make it so that when I click on one... It'll open a designated new window.
Help would be really appreciated.

Thanks,
Anton
 
I'm not on my dev machine so I can't test this, but I think something like this might be what you're looking for.

1st: make the class implement OnClickListener
Code:
public class ExpandableList3 extends ExpandableListActivity implements OnClickListener {
2nd: Add the code to handle the click:
Code:
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.item_X:
                // do something
            case R.id.item_Y:
                // do something else
        }
    }
 
Upvote 0
Hi,
I need help!!! my code is near the page. And my question is:

I want to show the word image by clicking on the word. How can I create onclicklistener in the ExpandableList?

Thanks

public class Categories extends ExpandableListActivity {

private static final String NAME = "NAME";


private ExpandableListAdapter mAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DBManager db = new DBManager(getApplicationContext());

List<String> header = db.selectAllCategories();
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();

for (String category : header) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, category);


List<String> categoryWords = db.selectWordsFromCategory(category);

List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (String word : categoryWords) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);

curChildMap.put(NAME, word);

}
childData.add(children);
}


mAdapter = new SimpleExpandableListAdapter(
this,
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME },
new int[] { android.R.id.text1 },
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME },
new int[] { android.R.id.text1 }
);

setListAdapter(mAdapter);
}


}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones