Android ExpandableListView在下面打开新活动

Android ExpandableListView在下面打开新活动,android,expandablelistview,Android,Expandablelistview,我想显示一个活动当我在ExpandableListview中单击组时,我试图将意图放在onGroupExpand上以打开新活动而不是子列表。但当它只打开活动时。当我点击群组时,我想在下面显示它。这是我的密码 package pack.ExpandableListtwo; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.app.ExpandableListAct

我想显示一个活动当我在ExpandableListview中单击组时,我试图将意图放在onGroupExpand上以打开新活动而不是子列表。但当它只打开活动时。当我点击群组时,我想在下面显示它。这是我的密码

package pack.ExpandableListtwo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;

 public class ExpandableListDemo extends ExpandableListActivity {

@SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
    try {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);

    SimpleExpandableListAdapter expListAdapter =
        new SimpleExpandableListAdapter(
                this,
                createGroupList(),              
                R.layout.group_row,                         
                new String[] { "Group Item" },  
                new int[] { R.id.row_name },                        
                createChildList(),              
                R.layout.child_row,             
                new String[] {"Sub Item"},      
                new int[] { R.id.grp_child}     
            );
        setListAdapter( expListAdapter );       

    }catch(Exception e){
        System.out.println("Errrr +++ " + e.getMessage());
    }
}

/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
      ArrayList result = new ArrayList();
      for( int i = 0 ; i < 3 ; ++i ) { // 3 groups........
        HashMap m = new HashMap();
        m.put( "Group Item","Group Item " + i ); // the key and it's value.
        result.add( m );
      }
      return (List)result;
}

/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList() {

    ArrayList result = new ArrayList();
    for( int i = 0 ; i < 3 ; ++i ) { // this -3 is the number of groups(Here it's fifteen)
      /* each group need each HashMap-Here for each group we have 3 subgroups */
      ArrayList secList = new ArrayList(); 
      Intent intent = new Intent(getApplicationContext(),
              MainActivity.class);
      startActivity(intent);
     result.add( secList );
    }        
    return result;
}
public void  onContentChanged  () {
    System.out.println("onContentChanged");
    super.onContentChanged();         
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {


        return true;
    } 

/* This function is called on expansion of the group */
public void  onGroupExpand  (int groupPosition) {
    try{
         System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);

    }catch(Exception e){
        System.out.println(" groupPosition Errrr +++ " + e.getMessage());

        Intent intent = new Intent(getApplicationContext(),
                MainActivity.class);
             startActivity(intent);

    }
}  
}
package pack.expandablelist2;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.List;
导入android.app.ExpandableListActivity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.ExpandableListAdapter;
导入android.widget.ExpandableListView;
导入android.widget.SimpleExpandableListAdapter;
公共类ExpandableListDemo扩展了ExpandableListActivity{
@抑制警告(“未选中”)
创建时的公共void(Bundle savedInstanceState){
试一试{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SimpleExpandableListAdapter解释适配器=
新的SimpleExpandableListAdapter(
这
createGroupList(),
R.layout.group_行,
新字符串[]{“组项”},
新int[]{R.id.row_name},
createChildList(),
R.layout.child_行,
新字符串[]{“子项”},
新int[]{R.id.grp_child}
);
setListAdapter(expListAdapter);
}捕获(例外e){
System.out.println(“Errrr++”+e.getMessage());
}
}
/*为行创建Hashmap*/
@抑制警告(“未选中”)
私有列表createGroupList(){
ArrayList结果=新建ArrayList();
对于(int i=0;i<3;++i){//3组。。。。。。。。
HashMap m=新的HashMap();
m、 put(“组项”,“组项”+i);//键及其值。
结果:添加(m);
}
返回(列表)结果;
}
/*为孩子们创建HashMap*/
@抑制警告(“未选中”)
私有列表createChildList(){
ArrayList结果=新建ArrayList();
对于(inti=0;i<3;++i){//这-3是组数(这里是15)
/*每个组都需要每个HashMap。对于每个组,我们有3个子组*/
ArrayList secList=新的ArrayList();
意向意向=新意向(getApplicationContext(),
主要活动(课堂);
星触觉(意向);
结果。添加(secList);
}        
返回结果;
}
内容更改时的公共无效(){
System.out.println(“onContentChanged”);
super.onContentChanged();
}
/*每次单击子项时都会调用此函数*/
公共布尔onChildClick(ExpandableListView父视图、视图v、int-groupPosition、int-childPosition、长id){
返回true;
} 
/*此函数在组扩展时调用*/
public void onGroupExpand(int groupPosition){
试一试{
System.out.println(“组扩展侦听器=>groupPosition=“+groupPosition”);
}捕获(例外e){
System.out.println(“grouppositionerrrr++”+e.getMessage());
意向意向=新意向(getApplicationContext(),
主要活动(课堂);
星触觉(意向);
}
}  
}

正如Aleks所说,这是不可能的,因为每个活动只能包含一个布局,尽管您可以使用某种从下到上的动画,或者使用可见性隐藏和显示同一xml中的另一个布局,您可以将其放在ExpnadibleListView下面。

如果我正确理解您的要求,您希望打开另一个活动作为屏幕的一部分,而不是替换屏幕上的现有活动。这在Android中是不可能的。如果您想在listview下面显示一些内容,请阅读有关片段的内容。