I am so close but can't figure it out. I am trying to pass both Strings movieGroup and movieName to the new activity. The way I have it I can only do one or the other. I would like both to come to a new activity
public class MainActivity extends Activity {
public final static String ID_EXTRA = "com.example.chris.prontopages2.Main22Activity.";
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) {
String movieGroup = Movies_list.get(groupPosition);
String movieName = Movies_category.get(Movies_list.get(groupPosition)).get(childPosition);
Intent i = new Intent(MainActivity.this,Main22Activity.class);
Bundle extras = i.getExtras();
i.putExtra(ID_EXTRA ,movieGroup);
i.putExtra(ID_EXTRA ,movieName);
startActivity(i);
return false;
}
});
}
}
Use different keys for movieGroup
and movieName
. Something like this,
i.putExtra(ID_EXTRA + "movieGroup" ,movieGroup);
i.putExtra(ID_EXTRA + "movieName" ,movieName);
And in Main22Activity
, retrieve it like this,
Bundle extras = getIntent().getExtras();
String movieGroup = extras.getString(ID_EXTRA + "movieGroup");
String movieName = extras.getString(ID_EXTRA + "movieName");
Give the extras different names, now the second one is overwriting the first
i.putExtra(ID_EXTRA ,movieGroup);
i.putExtra(ID_EXTRA ,movieName);
Change it to somthing like (or declare separate constants)
i.putExtra(ID_EXTRA + "group" ,movieGroup);
i.putExtra(ID_EXTRA + "name" ,movieName);
and then use those names in the Main22Activity.class
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.