Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Aug 2011
    Location
    The Milky Way Galaxy
    Posts
    5
    Blog Entries
    1

    Device(s)
    CliqXT 1.5 Rooted CliqXT 2.1 myTouch 2.2

    ExpandedListView Longpress problems (onCreateContextMenu)

    Hi all
    Can anybody enlighten me on whats wrong with this code. I would think this should be bringing up a context menu when I longpress a child item. Is there something else I should add? The Overriden methods and a call in the onCreate is all that is needed with Simple_item_list but apparently not with Expanded..


    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import android.app.ExpandableListActivity;
    import android.os.Bundle;
    import android.view.ContextMenu;
    import android.view.ContextMenu.ContextMenuInfo;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.ExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.ListView;
    import android.widget.SimpleExpandableListAdapter;
    import android.widget.Toast;

    public class ExpandListTrialActivity extends ExpandableListActivity {
    private static final String NAME = "NAME";
    private static final String IS_EVEN = "IS_EVEN";

    private ExpandTrialDbAdapter mDbHelper;
    private ExpandableListAdapter mAdapter;


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

    mDbHelper = new ExpandTrialDbAdapter(this);
    mDbHelper.open();

    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);
    registerForContextMenu(getExpandableListView());
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
    ContextMenuInfo menuInfo){
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater mi = getMenuInflater();
    mi.inflate(R.menu.longpress, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item){
    switch (item.getItemId()){
    case R.id.item1:

    return true;
    }
    return super.onContextItemSelected(item);
    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id){
    super.onChildClick(parent, v, groupPosition, childPosition, id);
    Toast.makeText(getApplicationContext(), "Its Working",
    Toast.LENGTH_LONG).show();
    return super.onChildClick(parent, v, groupPosition, childPosition, id);
    }

    }

  2. #2
    Member
    Join Date
    Aug 2011
    Location
    The Milky Way Galaxy
    Posts
    5
    Blog Entries
    1

    Device(s)
    CliqXT 1.5 Rooted CliqXT 2.1 myTouch 2.2

    Original Poster
    Ok, after looking into the expandlist samples in the sdk i can see the simple expand lists are not nearly as simple as the simple item lists. Im making headway, perhaps ill post my own answer.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •