如何在android中隐藏可扩展列表

如何在android中隐藏可扩展列表,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,我在一个活动中有3个可展开的列表 我在第一个可展开列表中有两个单选按钮,当我单击第一个单选按钮时,它应该隐藏第二个可展开列表,如果我选择2个单选按钮,它应该隐藏第三个可展开列表 我该怎么做 我已经发布了我的代码部分 public class MyActivity extends Activity { ExpandableListAdapter listAdapter; ExpandableListView expListView; List<String>

我在一个活动中有3个可展开的列表

我在第一个可展开列表中有两个单选按钮,当我单击第一个单选按钮时,它应该隐藏第二个可展开列表,如果我选择2个单选按钮,它应该隐藏第三个可展开列表

我该怎么做

我已经发布了我的代码部分

public class MyActivity 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.my_activity);

        // 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);
    }

    /*
     * Preparing the list data
     */
    private void prepareListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add("Checkout Method");
        listDataHeader.add("Create Account");
        listDataHeader.add("Bill Address");
        listDataHeader.add("Address");
        listDataHeader.add("Order");

        // Adding child data
        List<String> top250 = new ArrayList<String>();
        top250.add("The Shawshank Redemption");
//        top250.add("The Godfather");
//        top250.add("The Godfather: Part II");
//        top250.add("Pulp Fiction");
//       

        List<String> nowShowing = new ArrayList<String>();
        nowShowing.add("The Conjuring");
//        nowShowing.add("Despicable Me 2");
//        nowShowing.add("Turbo");
//        nowShowing.add("Grown Ups 2");
//        nowShowing.add("Red 2");
//        nowShowing.add("The Wolverine");
// 
        List<String> comingSoon = new ArrayList<String>();
        comingSoon.add("2 Guns");
//        comingSoon.add("The Smurfs 2");
//        comingSoon.add("The Spectacular Now");
//        comingSoon.add("The Canyons");
//        comingSoon.add("Europa Report");
// 
        listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
        listDataChild.put(listDataHeader.get(1), nowShowing);
        listDataChild.put(listDataHeader.get(2), comingSoon);
    }
}
公共类MyActivity扩展活动{
可扩展列表适配器;
ExpandableListView解释视图;
列表列表数据头;
HashMapListDataChild;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.my_活动);
//获取列表视图
expListView=(ExpandableListView)findViewById(R.id.lvExp);
//准备列表数据
prepareListData();
listAdapter=新的ExpandableListAdapter(此,listDataHeader,listDataChild);
//设置列表适配器
expListView.setAdapter(listAdapter);
}
/*
*准备列表数据
*/
私有void prepareListData(){
listDataHeader=新的ArrayList();
listDataChild=newHashMap();
//添加子数据
添加(“签出方法”);
添加(“创建帐户”);
listDataHeader.add(“账单地址”);
添加(“地址”);
添加(“订单”);
//添加子数据
List top250=新的ArrayList();
top250.添加(“肖申克的救赎”);
//添加(“教父”);
//top250.添加(“教父:第二部分”);
//top250.添加(“低俗小说”);
//       
List nowShowing=新建ArrayList();
现在显示。添加(“变戏法”);
//添加(“卑鄙的我2”);
//现在显示。添加(“Turbo”);
//现在显示。添加(“成年人2”);
//现在显示。添加(“红色2”);
//现在显示。添加(“狼獾”);
// 
List comingSoon=新建ArrayList();
很快就来。添加(“2支枪”);
//很快就来。添加(“蓝精灵2”);
//即将到来。添加(“现在的壮观”);
//即将到来。添加(“峡谷”);
//即将出版。添加(“欧罗巴报告”);
// 
listDataChild.put(listDataHeader.get(0),top250);//头,子数据
listDataChild.put(listDataHeader.get(1),现在显示);
listDataChild.put(listDataHeader.get(2),即将出现);
}
}
公共类ExpandableListAdapter扩展了BaseExpandableListAdapter {

私有上下文myContext;
私有列表_listDataHeader;//头标题
//标题标题、子标题格式的子数据
私有HashMap_listDataChild;
编辑文本用户、电子邮件、通行证、重新通行证;
字符串用户名、emailid、密码、重新密码、成功;
EditText国家、fname、lname、公司、地址1、地址2、城市、州;
字符串CONN、fn、ln、com、ad1、ad2、ci、st、po;
EditText country1、fname1、lname1、comp1、addr11、addr21、city1、state1;
字符串CONN1、fn1、ln1、com1、ad11、ad21、ci1、st1;
复选框ch1;
无线按钮;
放射组rg;
内部rid;
按钮cbtn;
公共ExpandableListAdapter(上下文、列表listDataHeader、,
HashMap listChildData)
{
this.myContext=上下文;
这。_listDataHeader=listDataHeader;
这。_listDataChild=listChildData;
}
@凌驾
公共对象getChild(int-groupPosition、int-ChildPosition)
{
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition))
.get(childpositionon);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition)
{
返回子位置;
}
@凌驾
公共视图getChildView(最终int-groupPosition、int-childPosition、布尔isLastChild、视图convertView、视图组父级)
{
最终字符串childText=(字符串)getChild(groupPosition,childPosition);
int itemType=getChildType(groupPosition,childPosition);
LayoutInflater infalInflater=(LayoutInflater)this.myContext.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
/*
if(convertView==null)
{
convertView=infalInflater.充气(R.layout.expandable\u list\u项,空);
}
*/
开关(组位置)
{
案例0:
最终LayoutFlater充气器=(LayoutFlater)myContext.getSystemService(Context.LAYOUT\u充气器\u服务);
convertView=充气机。充气(R.layout.child_行,空);
rg=(放射组)convertView.findViewById(R.id.cradioGroup1);
cbtn=(按钮)convertView.findViewById(R.id.continebutton1);
cbtn.setOnClickListener(新的OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
//TODO自动生成的方法存根
//android:groupIndicator=“@android:color/transparent”
//.setVisibility(View.INVISIBLE);
}
});
rid=rg.getCheckedRadioButtonId();
rbutton=(RadioButton)convertView.findViewById(rid);
System.out.println(“+rbutton.getText());
打破
案例1:
LayoutFlater充气器1=(LayoutFlater)myContext.getSystemService(Context.LAYOUT\u充气器\u服务);
convertView=充气机1.充气(R.layout.child_row1,空);
//TextView tvPlayerName=(TextView)convertView.findViewById(R.id.tvPlayerName);
//tvPlayerName1.setText(arrChildelements[groupPosition][childPosition]);
user=(EditText)convertView.findViewById(R.id.editText1);
email=(EditText)convertView.findViewById(R.id.editText2);
pass=(EditText)convertView.findViewById(R.id.editText3);
repass=(EditText)convertView.findViewById(R.id.editText4);
按钮注册;
reg=(按钮)convertView.findViewById(R.id.button1);
reg.setOnClickListener(新的OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
//TODO自动生成的方法存根
private Context myContext;

private List<String> _listDataHeader; // header titles

// child data in format of header title, child title

private HashMap<String, List<String>> _listDataChild;

EditText user,email,pass,repass;

String username,emailid,password,repassword,success;

EditText country,fname,lname,comp,addr1,addr2,city,state;

String coun,fn,ln,com,ad1,ad2,ci,st,po;

EditText country1,fname1,lname1,comp1,addr11,addr21,city1,state1;
String coun1,fn1,ln1,com1,ad11,ad21,ci1,st1;

CheckBox ch1; 

RadioButton rbutton;

RadioGroup rg;

int rid;

Button cbtn;

public ExpandableListAdapter(Context context, List<String> listDataHeader,
        HashMap<String, List<String>> listChildData) 
{
    this.myContext = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}

@Override
public Object getChild(int groupPosition, int childPosititon)
{
    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .get(childPosititon);
}

@Override
public long getChildId(int groupPosition, int childPosition)
{
    return childPosition;
}

@Override
public View getChildView(final int groupPosition,  int childPosition,boolean isLastChild, View convertView, ViewGroup parent)
{

    final String childText = (String) getChild(groupPosition, childPosition);

    int itemType=getChildType(groupPosition,childPosition);

    LayoutInflater infalInflater = (LayoutInflater) this.myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

   /*
    if (convertView == null) 

    {
       convertView = infalInflater.inflate(R.layout.expandable_list_item, null);

    }
    */
    switch (groupPosition)
        {

        case 0:

            final LayoutInflater inflater =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater.inflate(R.layout.child_row, null);

            rg=(RadioGroup)convertView.findViewById(R.id.cradioGroup1);

            cbtn=(Button)convertView.findViewById(R.id.continebutton1);

            cbtn.setOnClickListener(new OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {
                    // TODO Auto-generated method stub
                    //android:groupIndicator="@android:color/transparent"
                    //.setVisibility( View.INVISIBLE );

                }
            });

            rid=rg.getCheckedRadioButtonId();

            rbutton=(RadioButton)convertView.findViewById(rid);

            System.out.println("<------Checked account in expandable adapter----->"+rbutton.getText());

            break;

        case 1:

            LayoutInflater inflater1 =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater1.inflate(R.layout.child_row1, null);

            //TextView tvPlayerName1 = (TextView) convertView.findViewById(R.id.tvPlayerName);

            //tvPlayerName1.setText(arrChildelements[groupPosition][childPosition]);

            user=(EditText)convertView.findViewById(R.id.editText1);

            email=(EditText)convertView.findViewById(R.id.editText2);

            pass=(EditText)convertView.findViewById(R.id.editText3);

            repass=(EditText)convertView.findViewById(R.id.editText4);

            Button reg;

            reg=(Button)convertView.findViewById(R.id.button1);

            reg.setOnClickListener(new OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {
                    // TODO Auto-generated method stub
                new Register().execute();   
                }
            });
            break; 

        case 2:

            LayoutInflater inflater2 =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater2.inflate(R.layout.child_row2, null);

            country=(EditText)convertView.findViewById(R.id.editcoun);

            fname=(EditText)convertView.findViewById(R.id.editfn);

            lname=(EditText)convertView.findViewById(R.id.editln);

            comp=(EditText)convertView.findViewById(R.id.editco);

            addr1 =(EditText)convertView.findViewById(R.id.editad1);

            addr2=(EditText)convertView.findViewById(R.id.editad2);

            city=(EditText)convertView.findViewById(R.id.editcity);



            Button reg1;

            reg1=(Button)convertView.findViewById(R.id.accbtn);

            reg1.setOnClickListener(new OnClickListener()
            {

                @Override
                public void onClick(View v) 
                {
                    // TODO Auto-generated method stub
                new B().execute();  
                }
            });
            break;

        case 3:             

            LayoutInflater inflater3 =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater3.inflate(R.layout.child_row3, null);

            ch1=(CheckBox)convertView.findViewById(R.id.check1);

            country1=(EditText)convertView.findViewById(R.id.editcoun1);

            fname1=(EditText)convertView.findViewById(R.id.editfn1);

            lname1=(EditText)convertView.findViewById(R.id.editln1);

            comp1=(EditText)convertView.findViewById(R.id.editco1);

            addr11 =(EditText)convertView.findViewById(R.id.editad11);

            addr21=(EditText)convertView.findViewById(R.id.editad21);

            city1=(EditText)convertView.findViewById(R.id.editcity1);




             break;

        case 4:             

            LayoutInflater inflater4 =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = inflater4.inflate(R.layout.child_row4, null);

            Button place;

            place=(Button)convertView.findViewById(R.id.obutton1);

            place.setOnClickListener(new OnClickListener() 
            {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                Toast.makeText(myContext, "Thank you for your Purchase", Toast.LENGTH_SHORT).show();

                }
            });



             break;


        }


   /* TextView txtListChild = (TextView) convertView
            .findViewById(R.id.lblListItem);

    txtListChild.setText(childText);*/
    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
}

@Override
public Object getGroup(int groupPosition) {
    return this._listDataHeader.get(groupPosition);
}

@Override
public int getGroupCount() {
    return this._listDataHeader.size();
}

@Override
public long getGroupId(int groupPosition) {
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) 
{
    String headerTitle = (String) getGroup(groupPosition);

    if (convertView == null)
    {
        LayoutInflater infalInflater = (LayoutInflater) this.myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = infalInflater.inflate(R.layout.expandable_list_group, null);
    }

    TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);

    lblListHeader.setTypeface(null, Typeface.BOLD);

    lblListHeader.setText(headerTitle);

    return convertView;
}

@Override
public boolean hasStableIds() 
{
    return false;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) 
{
    return true;
}
switch (groupPosition)
            {

            case 0:

                final LayoutInflater inflater =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                convertView = inflater.inflate(R.layout.child_row, null);

                rg=(RadioGroup)convertView.findViewById(R.id.cradioGroup1);

                cbtn=(Button)convertView.findViewById(R.id.continebutton1);

                cbtn.setOnClickListener(new OnClickListener() 
                {

                    @Override
                    public void onClick(View v) 
                    {
                        // TODO Auto-generated method stub
                        //android:groupIndicator="@android:color/transparent"
                        //.setVisibility( View.INVISIBLE );

                    }
                });

                rid=rg.getCheckedRadioButtonId();

                rbutton=(RadioButton)convertView.findViewById(rid);

                System.out.println("<------Checked account in expandable adapter----->"+rbutton.getText());

                break;

            case 1:

                LayoutInflater inflater1 =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                convertView = inflater1.inflate(R.layout.child_row1, null);

                //TextView tvPlayerName1 = (TextView) convertView.findViewById(R.id.tvPlayerName);

                //tvPlayerName1.setText(arrChildelements[groupPosition][childPosition]);

                user=(EditText)convertView.findViewById(R.id.editText1);

                email=(EditText)convertView.findViewById(R.id.editText2);

                pass=(EditText)convertView.findViewById(R.id.editText3);

                repass=(EditText)convertView.findViewById(R.id.editText4);

                Button reg;

                reg=(Button)convertView.findViewById(R.id.button1);

                reg.setOnClickListener(new OnClickListener() 
                {

                    @Override
                    public void onClick(View v) 
                    {
                        // TODO Auto-generated method stub
                    new Register().execute();   
                    }
                });
                break; 

            case 2:

                LayoutInflater inflater2 =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                convertView = inflater2.inflate(R.layout.child_row2, null);

                country=(EditText)convertView.findViewById(R.id.editcoun);

                fname=(EditText)convertView.findViewById(R.id.editfn);

                lname=(EditText)convertView.findViewById(R.id.editln);

                    break;
cbtn.setOnClickListener(new OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {
                    // TODO Auto-generated method stub
               rid=rg.getCheckedRadioButtonId();

               rbutton1=(RadioButton)convertView.findViewById(R.id.rid1);
                  rbutton2=(RadioButton)convertView.findViewById(R.id.rid2); 
                radiomain = (RadioButton) findViewById(rid);
               if(radiomain.getText().toString().equals(rbutton1.gettext().toString)
                     exp1.setVisibility(View.INVISIBLE);
               else
                    exp2.setVisibility(View.INVISIBLE);


                }
            });
expandablelist.setvisibility(View.GONE); // in this scenario view are gone complatelly from layout.
expandablelist.setvisibility(View.INVISIBLE); // in this scenario view are cover space in layout, but not visible in layout.
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  setContentView(R.layout.mylistviewlayout);

  tb = (ToggleButton) findViewById(R.id.toggleButton1);
  lv = (ListView) findViewById(R.id.listView1);

  //You could set ListView Adapter here.

  tb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

          if(isChecked)
          {
              lv.setVisibility(View.VISIBLE);
          }
          else
          {
              //lv.setVisibility(View.GONE);
              lv.setVisibility(View.INVISIBLE);
          }
      }
  });
}