0

My main activity is a list activity that pretty much lists the different terms for school. Once a term is clicked it will bring up a new page(activity) another list activity that shows all the courses in that term.

Is there a way where we can check if say term 1 or term 2 has been clicked on the main activity in the 2nd page/activity? For example my 2nd activity have different methods called populateTermX where X = term number. In the onCreate method it will do a check to see which term got clicked in the main activity and will call the populateTermX methods. That way I don't have to make like a bunch of different activities to correspond with the terms.

Code: Main Activity

protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

    populateList();
}

private void populateList() {
    String[] terms = {// terms in here};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(), android.R.layout.simple_list_item_1, terms);
    getListView().setAdapter(adapter);
}

Code: 2nd Activity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course);
    if(term1 is clicked) {
       populateTerm1();
    } // etc...
}

private void populateTerm1() {
    String[] courses = {//courses in here};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(), android.R.layout.simple_list_item_1, courses);
    getListView().setAdapter(adapter);
}

private void populateTerm2() {
    String[] courses = {//courses in here};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView.getContext(), android.R.layout.simple_list_item_1, courses);
    getListView().setAdapter(adapter);
}
SC.Cee
  • 237
  • 1
  • 4
  • 14
  • Have a look at this question http://stackoverflow.com/questions/768969/passing-a-bundle-on-startactivity – ElDuderino Oct 05 '16 at 07:33
  • use onItemClickListner() in list and there you will get the position of item clicked and than.... get that item and pass it to other activity using PutExtra(), and finally get this extra in other activity – Anwar Kamal Oct 05 '16 at 07:35
  • @Anwar Kamal thanks that did the trick. – SC.Cee Oct 06 '16 at 04:38

0 Answers0