Android 如何为位置设置颜色';0';可扩展列表视图的设计

Android 如何为位置设置颜色';0';可扩展列表视图的设计,android,expandablelistview,background-color,expandablelistadapter,Android,Expandablelistview,Background Color,Expandablelistadapter,我有四个活动类,我需要为四个活动实现四种不同的颜色,我有一个ExpandableListAdapter,如: public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context _context; private List<String> _listDataHeader; // header titles // child data in format of header ti

我有四个活动类,我需要为四个活动实现四种不同的颜色,我有一个ExpandableListAdapter,如:

public class ExpandableListAdapter extends BaseExpandableListAdapter {

private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
String colors;

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

@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(int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {

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

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, null);
    }

    CheckedTextView txtListChild = (CheckedTextView) convertView
            .findViewById(R.id.lblListItem);
    txtListChild.setTypeface(TypeFaceConstant.getGibsonregular(_context));
    txtListChild.setText(childText);

    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
    if(groupPosition==2){
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }else
        return 0;

}

@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._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_group, null);
    }

    CheckedTextView lblListHeader = (CheckedTextView) convertView
            .findViewById(R.id.lblListHeader);
    lblListHeader.setTypeface(TypeFaceConstant.getGibsonregular(_context));

    lblListHeader.setText(headerTitle);

    return convertView;
}

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

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}
公共类ExpandableListAdapter扩展了BaseExpandableListAdapter{
私人语境(private Context)(私人语境);;
私有列表_listDataHeader;//头标题
//标题标题、子标题格式的子数据
私有HashMap_listDataChild;
字符串颜色;
公共ExpandableListAdapter(上下文、列表listDataHeader、,
HashMap listChildData,字符串颜色){
这._context=context;
这。_listDataHeader=listDataHeader;
这。_listDataChild=listChildData;
这个。颜色=颜色;
}
@凌驾
公共对象getChild(int-groupPosition、int-ChildPosition){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition))
.get(childpositionon);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
@凌驾
公共视图getChildView(int groupPosition,final int childPosition,
布尔值isLastChild、视图转换视图、视图组父级){
最终字符串childText=(字符串)getChild(groupPosition,childPosition);
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.list_项,空);
}
CheckedTextView txtListChild=(CheckedTextView)convertView
.findviewbyd(R.id.lblListItem);
setTypeface(TypeFaceConstant.getGibsonregular(_context));
setText(childText);
返回视图;
}
@凌驾
公共整数getChildrenCount(整数组位置){
if(groupPosition==2){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition))
.size();
}否则
返回0;
}
@凌驾
公共对象getGroup(int-groupPosition){
返回此。\u listDataHeader.get(groupPosition);
}
@凌驾
public int getGroupCount(){
返回此值。_listDataHeader.size();
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
字符串头文件=(字符串)getGroup(groupPosition);
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.list_组,空);
}
CheckedTextView lblListHeader=(CheckedTextView)convertView
.findviewbyd(R.id.lblistheader);
lblListHeader.setTypeface(TypeFaceConstant.getGibsonregular(_context));
lblListHeader.setText(标题);
返回视图;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回true;
}
我的活动课是这样的:

 public class OfficeScreenActivity extends FragmentActivity implements OnClickListener {

LinearLayout office,roaster,food_service,hospitality;


ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
TextView lblListHeader,office_text;

ImageView play,logo,office_image;
LinearLayout ln;
Context context;
Bundle bundle;
ArrayList<Content> al;

HashMap<String, List<String>> listDataChild;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_office_screen);


    play=(ImageView) findViewById(R.id.play_button);
    logo=(ImageView) findViewById(R.id.logo_button);

    roaster=(LinearLayout) findViewById(R.id.roaster_lay);
    food_service=(LinearLayout) findViewById(R.id.food_lay);
    hospitality=(LinearLayout) findViewById(R.id.hosp_lay);

    office_image=(ImageView) findViewById(R.id.office_image);
    office_image.setImageResource(R.drawable.office_color);

    office_text=(TextView) findViewById(R.id.office_text);
    office_text.setTextColor(Color.parseColor("#57B7B2"));



    roaster.setOnClickListener(this);
    food_service.setOnClickListener(this);
    hospitality.setOnClickListener(this);
    play.setOnClickListener(this);
    logo.setOnClickListener(this);

    FragmentManager fm;
    IntroductionFragment fragment = new IntroductionFragment();
    Bundle bundle = new Bundle();
    String str="    office coffiee that will \n have everyone talking.";

    String str1="SOLA";
    String str2=" BEV OFFICE COFFEE SYSTEM SOLUTIONS";
    final String colors="#57B7B2";
    //bundle.putString("office",str);
    bundle.putString("sola", str1);
    bundle.putString("bev", str2);
    bundle.putString("office",str);
    bundle.putString("color", colors);
    fragment.setArguments(bundle);

        fm=getSupportFragmentManager();
        fm.beginTransaction().replace(R.id.frame1, fragment, "NewFragmentTag").commit(); 

    // get the listview
            expListView = (ExpandableListView) findViewById(R.id.lvExp);


            // preparing list data
            prepareListData();

            listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild,colors);

            // setting list adapter
            expListView.setAdapter(listAdapter);

            // Listview Group click listener

            //expListView.setBackgroundColor(Color.parseColor("#57B7B2"));
            expListView.setOnGroupClickListener(new OnGroupClickListener() {
                CheckedTextView lastClickedView;


                @Override
                public boolean onGroupClick(ExpandableListView parent, View v,
                        int groupPosition, long id) {


                    if(groupPosition==0){


                        FragmentManager fm;
                                IntroductionFragment fragment = new IntroductionFragment();
                                Bundle bundle = new Bundle();
                                String str="    office coffiee that will \n have everyone talking.";
                                String str1="SOLA";
                                String colors="#57B7B2";
                                String str2=" BEV OFFICE COFFEE SYSTEM SOLUTIONS";
                                bundle.putString("office",str);
                                bundle.putString("sola", str1);
                                bundle.putString("bev", str2);
                                bundle.putString("color", colors);
                                fragment.setArguments(bundle);

                                    fm=getSupportFragmentManager();
                                    fm.beginTransaction().replace(R.id.frame1, fragment, "NewFragmentTag").commit(); 


                    }
                    else if(groupPosition==1){


                        FragmentManager fm;
                                KeyPointsFragment fragment = new KeyPointsFragment();

                                Bundle bundle = new Bundle();
                            String token="office";
                                bundle.putString("office", token);
                                fragment.setArguments(bundle);

                                    fm=getSupportFragmentManager();
                                    fm.beginTransaction().replace(R.id.frame1, fragment, "NewFragmentTag").commit(); 

                    }
                    else if(groupPosition==3){


                        FragmentManager fm;
                                PresentationsFragment fragment = new PresentationsFragment();
                                Bundle bundle = new Bundle();
                                String str="PRESENTATIONS";
                                //String str1="SOLA";
                                String colors="#57B7B2";
                                //String str2=" BEV OFFICE COFFEE SYSTEM SOLUTIONS";
                                bundle.putString("present_title",str);
                                bundle.putString("cate_id", "1");
                                //bundle.putString("sola", str1);
                                //bundle.putString("bev", str2);
                                bundle.putString("color", colors);
                                fragment.setArguments(bundle);

                                    fm=getSupportFragmentManager();
                                    fm.beginTransaction().replace(R.id.frame1, fragment, "NewFragmentTag").commit(); 


                    }


                    if(null!=lastClickedView){  
                           lastClickedView.setBackgroundColor(Color.parseColor("#232323"));
                      }
                      CheckedTextView txt3=(CheckedTextView) v.findViewById(R.id.lblListHeader);
                      if(!(groupPosition==2)){
                           txt3.setBackgroundColor(Color.parseColor("#57B7B2"));
                           //txt3.setTypeface(TypeFaceConstant.getGibsonBold(getApplicationContext()));
                        lastClickedView=txt3;
                      } 

                    if(groupPosition==2){
                     lblListHeader = (TextView) v
                            .findViewById(R.id.lblListHeader);

                    lblListHeader.setTextColor(Color.parseColor("#B0AFAF"));
                    }


                    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) {
                    if(groupPosition==2){
                    lblListHeader.setTextColor(Color.parseColor("#FFFFFF"));
                    }
                    Toast.makeText(getApplicationContext(),
                            listDataHeader.get(groupPosition) + " Collapsed",
                            Toast.LENGTH_SHORT).show();

                }
            });

            // Listview on child click listener
            expListView.setOnChildClickListener(new OnChildClickListener() {
                CheckedTextView lastClickedView;
                @Override
                public boolean onChildClick(ExpandableListView parent, View v,
                        int groupPosition, int childPosition, long id) {
                    // TODO Auto-generated method stub
                    if(childPosition==0){


                          Intent mInHome1112 = new Intent(OfficeScreenActivity.this,BrewersActivity.class);
                          mInHome1112.putExtra("cate_id", "1");
                            OfficeScreenActivity.this.startActivity(mInHome1112);

                    }
                    else if(childPosition==1){

                          Intent mInHome1112 = new Intent(OfficeScreenActivity.this,CapsulesActivity.class);
                          mInHome1112.putExtra("cate_id", "1");
                          mInHome1112.putExtra("Avtivity", "Office");
                            OfficeScreenActivity.this.startActivity(mInHome1112);

                    }
                    if(null!=lastClickedView){  
                           lastClickedView.setBackgroundColor(Color.parseColor("#232323"));
                      }
                      CheckedTextView txt1=(CheckedTextView) v.findViewById(R.id.lblListItem);
                           txt1.setBackgroundColor(Color.parseColor("#57B7B2"));
                        lastClickedView=txt1;



                    Toast.makeText(
                            getApplicationContext(),
                            listDataHeader.get(groupPosition)
                                    + " : "
                                    + listDataChild.get(
                                            listDataHeader.get(groupPosition)).get(
                                            childPosition), Toast.LENGTH_SHORT)
                            .show();
                    return false;
                }
                });
        }
公共类OfficeScreenActivity扩展FragmentActivity实现OnClickListener{
直线布局办公室、烘焙店、餐饮服务、酒店;
可扩展列表适配器;
ExpandableListView解释视图;
列表列表数据头;
text视图lblistheader,office_text;
ImageView播放、徽标、办公室图像;
线性布局;
语境;
束;
ArrayList al;
HashMapListDataChild;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u office\u屏幕);
play=(ImageView)findviewbyd(R.id.play_按钮);
logo=(ImageView)findviewbyd(R.id.logo_按钮);
烘焙器=(线性布局)findViewById(R.id.烘焙器布局);
食品服务=(线性布局)查找到的视图(R.id.food\u lay);
酒店=(线性布局)FindViewbyd(R.id.hosp_-lay);
office\u image=(ImageView)findviewbyd(R.id.office\u image);
office_image.setImageResource(R.drawable.office_color);
office_text=(TextView)findViewById(R.id.office_text);
office#text.setTextColor(Color.parseColor(#57B7B2”);
roaster.setOnClickListener(此);
食品服务。setOnClickListener(本);
热情好客。setOnClickListener(本);
play.setOnClickListener(这个);
logo.setOnClickListener(此);
碎片管理器fm;
IntroductionFragment=新的IntroductionFragment();
Bundle=新Bundle();
String str=“办公室棺材,将\n让每个人都能说话。”;
字符串str1=“SOLA”;
String str2=“BEV办公咖啡系统解决方案”;
最终字符串颜色=“#57B7B2”;
//bundle.putString(“office”,str);
bundle.putString(“sola”,str1);
bundle.putString(“bev”,str2);
bundle.putString(“office”,str);
bundle.putString(“颜色”,colors);
fragment.setArguments(bundle);
fm=getSupportFragmentManager();
fm.beginTransaction().replace(R.id.frame1,fragment,“NewFragmentTag”).commit();
//获取列表视图
expListView=(ExpandableListView)findViewById(R.id.lvExp);
//准备列表数据
prepareListData();
listAdapter=新的ExpandableListAdapter(此,listDataHeader,listDataChild,颜色);
//设置列表适配器
expListView.setAdapter(listAdapter);
//Listview组单击侦听器
//expListView.setBackgroundColor(Color.parseColor(#57B7B2”);
expListView.setOnGroupClickListener(新OnGroupClickListener(){
CheckedTextView lastClickedView;
@凌驾
公共布尔值onGroupClick(ExpandableListView父视图,视图v,
int groupPosition,长id){
if(groupPosition==0){
碎片管理器fm;
IntroductionFragment=新的IntroductionFragment();
Bundle=新业务单元
if(groupPosition==0){
lblListHeader.setTextColor(<color passing in constructor>);
}