项目运行正常,案例3孩子点击确定,但是如果2点击它显示案例3中的活动或我在之前删除它的活动返回时显示我想要的活动 (当我点击微生物学时,它显示牙齿矫正,然后返回点击它显示微生物学)
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;
import com.freedental.blogspot.R;
public class MainActivity extends Activity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
// Listview Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
switch(groupPosition) {
case 1:
switch (childPosition) {
case 0:
Intent c1= new Intent(MainActivity.this,Webv1Activity.class);
startActivity(c1);
break;
}
case 2:
switch (childPosition) {
case 0:
Intent d1= new Intent(MainActivity.this,Webv1Activity.class);
startActivity(d1);
break;
case 1:
Intent d2= new Intent(MainActivity.this,Webv2Activity.class);
startActivity(d2);
break;
case 2:
Intent d3= new Intent(MainActivity.this,Webv3Activity.class);
startActivity(d3);
break;
case 3:
Intent d4= new Intent(MainActivity.this,Webv4Activity.class);
startActivity(d4);
break;
case 4:
Intent d5= new Intent(MainActivity.this,Webv5Activity.class);
startActivity(d5);
break;
case 5:
Intent d6= new Intent(MainActivity.this,Webv6Activity.class);
startActivity(d6);
break;
case 6:
Intent d7= new Intent(MainActivity.this,Webv7Activity.class);
startActivity(d7);
break;
case 7:
Intent d8= new Intent(MainActivity.this,Webv8Activity.class);
startActivity(d8);
break;
}
case 3:
switch (childPosition) {
case 0:
Intent a1= new Intent(MainActivity.this,Webv9Activity.class);
startActivity(a1);
break;
case 1:
Intent a2= new Intent(MainActivity.this,Webv10Activity.class);
startActivity(a2);
break;
case 2:
Intent a3= new Intent(MainActivity.this,Webv11Activity.class);
startActivity(a3);
break;
case 3:
Intent a4= new Intent(MainActivity.this,Webv12Activity.class);
startActivity(a4);
break;
case 4:
Intent a5= new Intent(MainActivity.this,Webv13Activity.class);
startActivity(a5);
break;
case 5:
Intent a6= new Intent(MainActivity.this,Webv14Activity.class);
startActivity(a6);
break;
case 6:
Intent a7= new Intent(MainActivity.this,Webv15Activity.class);
startActivity(a7);
break;
case 7:
Intent a8= new Intent(MainActivity.this,Webv16Activity.class);
startActivity(a8);
break;
}
}
return false;
}
});
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("1st Grade lectures");
listDataHeader.add("2nd Grade lectures");
listDataHeader.add("3rd Grade lectures");
listDataHeader.add("4th Grade lectures");
listDataHeader.add("5th Grade lectures");
// Adding child data
List<String> first = new ArrayList<String>();
first.add("Under Construction");
List<String> second = new ArrayList<String>();
second.add("Prosthodontics");
second.add("Other under con");
List<String> third = new ArrayList<String>();
third.add("Microbiology");
third.add("Pathology");
third.add("Pharmacology");
third.add("Surgery");
third.add("Operative");
third.add("Prosthodontics");
third.add("Radiology");
third.add("Cummunity");
List<String> fourth = new ArrayList<String>();
fourth.add("periodontology");
fourth.add("pedodontics");
fourth.add("Orthodontics");
fourth.add("Prosthodontics");
fourth.add("Oral Pathology");
fourth.add("Oral Surgery");
fourth.add("General Surgery");
fourth.add("General Medicine");
List<String> fifth = new ArrayList<String>();
fifth.add("Under Construction");
listDataChild.put(listDataHeader.get(0), first); // Header, Child data
listDataChild.put(listDataHeader.get(1), second);
listDataChild.put(listDataHeader.get(2), third);
listDataChild.put(listDataHeader.get(3), fourth);
listDataChild.put(listDataHeader.get(4), fifth);
}
}
答案 0 :(得分:0)
您在break
和case 1
之后错过了case 2
语句:
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
switch(groupPosition) {
case 1:
switch (childPosition) {
case 0:
Intent c1= new Intent(MainActivity.this,Webv1Activity.class);
startActivity(c1);
break;
}
=======>>>>> break;
case 2:
switch (childPosition) {
case 0:
Intent d1= new Intent(MainActivity.this,Webv1Activity.class);
startActivity(d1);
break;
case 1:
Intent d2= new Intent(MainActivity.this,Webv2Activity.class);
startActivity(d2);
break;
case 2:
Intent d3= new Intent(MainActivity.this,Webv3Activity.class);
startActivity(d3);
break;
case 3:
Intent d4= new Intent(MainActivity.this,Webv4Activity.class);
startActivity(d4);
break;
case 4:
Intent d5= new Intent(MainActivity.this,Webv5Activity.class);
startActivity(d5);
break;
case 5:
Intent d6= new Intent(MainActivity.this,Webv6Activity.class);
startActivity(d6);
break;
case 6:
Intent d7= new Intent(MainActivity.this,Webv7Activity.class);
startActivity(d7);
break;
case 7:
Intent d8= new Intent(MainActivity.this,Webv8Activity.class);
startActivity(d8);
break;
}
==========>>>>> break;
case 3:
switch (childPosition) {
case 0:
Intent a1= new Intent(MainActivity.this,Webv9Activity.class);
startActivity(a1);
break;
case 1:
Intent a2= new Intent(MainActivity.this,Webv10Activity.class);
startActivity(a2);
break;
case 2:
Intent a3= new Intent(MainActivity.this,Webv11Activity.class);
startActivity(a3);
break;
case 3:
Intent a4= new Intent(MainActivity.this,Webv12Activity.class);
startActivity(a4);
break;
case 4:
Intent a5= new Intent(MainActivity.this,Webv13Activity.class);
startActivity(a5);
break;
case 5:
Intent a6= new Intent(MainActivity.this,Webv14Activity.class);
startActivity(a6);
break;
case 6:
Intent a7= new Intent(MainActivity.this,Webv15Activity.class);
startActivity(a7);
break;
case 7:
Intent a8= new Intent(MainActivity.this,Webv16Activity.class);
startActivity(a8);
break;
}
}
return false;
}
});