Note that there are some explanatory texts on larger screens.

plurals
  1. POAnother Method for calling activities.?
    text
    copied!<p>So here is my code.. I have a lot activities to be switched between and this code seems to work perfectly. But I was wondering if there is another method which is less complicate and easy to implement rather than "SWITCH CASE" method.</p> <p>enter code here</p> <pre><code>package com.prashant.dfs; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; public class Chapter_1_full extends Activity { ExpandableListAdapter listAdapter; ExpandableListView expListView; List&lt;String&gt; ListDataHeader; HashMap&lt;String,List&lt;String&gt;&gt; listDataChild; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chapter_1_full); //get the listView(expand) expListView = (ExpandableListView) findViewById(R.id.ch1_expand); //prepareDataList prepareListData(); listAdapter=new ExpandableListAdapter(this, ListDataHeader, listDataChild); expListView.setAdapter(listAdapter); } private void prepareListData() { ListDataHeader = new ArrayList&lt;String&gt;(); listDataChild=new HashMap&lt;String, List&lt;String&gt;&gt;(); //Adding child Data ListDataHeader.add("1.1 Introductin to Algorithms"); ListDataHeader.add("1.2 Data Structures"); ListDataHeader.add("1.3 ADT"); List&lt;String&gt; Intro = new ArrayList&lt;String&gt;(); Intro.add("Algoithem Design "); Intro.add("Flowcharting"); Intro.add("Pseudo-Language"); List&lt;String&gt; dataStructure = new ArrayList&lt;String&gt;(); dataStructure.add("Type of Data Structure"); dataStructure.add("Primitive and Non-Primitive"); dataStructure.add("Linear and Non-Linear"); dataStructure.add("Static and Dynamic"); List&lt;String&gt; ADT = new ArrayList&lt;String&gt;(); ADT.add("Datat Object"); listDataChild.put(ListDataHeader.get(0),Intro); listDataChild.put(ListDataHeader.get(1),dataStructure); listDataChild.put(ListDataHeader.get(2),ADT); expListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { final Object childObj=parent.getExpandableListAdapter().getChild(groupPosition, childPosition); if(childObj!=null) { switch (groupPosition) { case 0: { switch (childPosition) { case 0: { startActivity(new Intent(Chapter_1_full.this,TestActivity.class)); break; } case 1: { startActivity(new Intent(Chapter_1_full.this,TestActivity2.class)); break; } case 2: { startActivity(new Intent(Chapter_1_full.this,TestActivity3.class)); break; } } break; } case 1: startActivity(new Intent(Chapter_1_full.this,TestActivity4.class)); } } return true; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.chapter_1_full, menu); return true; } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload