0

Hi I am new to programming and was having a lot of fun starting until I copied a tutorial for an expandable list and have been stuck for over 1 week.

I'm trying to use the final selection from an expandable list and pass this information to my new activity. The way it is set up now is I can pass the string value id (I don't want this) I want the actual string that was clicked.

public class MainActivity extends Activity {
public final static String ID_EXTRA = "com.example.chris.prontopages2.MainActivity.";
HashMap<String, List<String>> Movies_category;
List<String> Movies_list;
ExpandableListView Exp_list;
MoviesAdapter adapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Exp_list = (ExpandableListView) findViewById(R.id.exp_list);
    Movies_category = DataProvider.getInfo();
    Movies_list = new ArrayList<String>(Movies_category.keySet());
    adapter = new MoviesAdapter(this, Movies_category, Movies_list);
    Exp_list.setAdapter(adapter);

    Exp_list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            Intent i = new Intent("Main22Activity.class");
            i.putExtra(ID_EXTRA, String.valueOf(id));
            startActivity(i);
            return false;

        }
    });

}
myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33
john smith
  • 89
  • 1
  • 1
  • 5

2 Answers2

0

You can use the following to get the element at the given position

ExpandableListAdapter itemAdapter = parent.getExpandableListAdapter(); 
String selectedItem = (String) itemAdapter.getChild(groupPosition, childPosition);

and then pass it on in your intent.

myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33
0

You do not need to pass the id of child selection. try this this will help you.

 Exp_list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

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

String movieName = Movies_category.get(Movies_list.get(groupPosiion)).get(childPosition)
                Intent i = new Intent("Main22Activity.class");
                i.putExtra(ID_EXTRA, movieName);
                startActivity(i);
                return false;

            }
        });

and get this extra in other activity.

Umesh Saraswat
  • 560
  • 1
  • 8
  • 22