package com.icube.platform;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import com.icube.timbodi.R;
import com.icube.timbodi.calendar.CalendarView;
import com.icube.timbodi.player.ChosePlayerView;
import com.icube.timbodi.scorecenter.PlayerlistActivity;
import com.icube.timbodi.user.ChangePassword;
import com.icube.timbodi.user.DashBoard;
import com.icube.timbodi.user.LandingActivity;
import com.icube.timbodi.user.UserFans;
class MenuLabel
{
public Button button;
public MenuLabel() {
// TODO Auto-generated constructor stub
}
public MenuLabel(Button button ) {
this.button=button;
this.button.setText("ram");
}
public void setText(String str)
{
button.setText(str);
}
}
public class SlidingAdapter extends BaseExpandableListAdapter implements OnClickListener{
Context context;
int layoutResourceId;
MenuLabel data[] = null;
String[] menuLabel;
int[] menuIcon;
Intent intent;
String[][] subMenuLabel={{"1","2","3"},{"4","5","6"},{"7","8","9"},{"9","8","7","6"},{"5","4","3"},{"3","2","1"},{"2","3","4","5"},{"1","3","2"}};
public LayoutInflater minflater;
public Activity activity;
public SlidingAdapter(Context context, int layoutResourceId, MenuLabel[] data,String[] menuLabel,int[] menuIcon)
{
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.menuLabel=menuLabel;this.menuIcon=menuIcon;
System.out.println("@@@@@@@+++++++++++++++++@@@@@@@@@@@@@@@@@@@@@@@@@@");
}
/* @Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
SlidingLabelHolder holder = null;
final int p=position;
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new SlidingLabelHolder();
holder.button=(Button)row.findViewById(R.id.sliding_menu);
holder.button.setText(" "+menuLabel[position]);
Drawable img = context.getResources().getDrawable( menuIcon[position] );
img.setBounds( 0, 0, 40, 40 );
holder.button.setCompoundDrawables( img, null, null, null );
holder.button.setId(position);
holder.button.setOnClickListener(this);
//row.setTag(0, holder);
//row.setTag(holder);
MenuLabel menuLabel = data[position];
holder.txtTitle.setText(menuLabel.title);
holder.imgIcon.setImageResource(menuLabel.icon);
return row;
}
*/
public void setInflater(LayoutInflater mInflater, Activity act) {
this.minflater = mInflater;
activity = act;
}
@Override
public Object getChild(int arg0, int arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getChildId(int arg0, int arg1) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
String str[]=subMenuLabel[groupPosition];
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
System.out.println("@@@@@@@@@@@@@@@dev@@@@@@@@@@+++++++++++++++++@@@@@@@@@@@@@@@@@@@@@@@@@@");
Button button=(Button)convertView.findViewById(R.id.sliding_menu);
button.setText(">"+str[childPosition]);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
System.out.println("1"+"##############");
return subMenuLabel[groupPosition].length-1;
}
@Override
public Object getGroup(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getGroupCount() {
System.out.println("2"+"##############"+ (menuLabel.length-1));
return menuLabel.length;
}
@Override
public void onGroupCollapsed(int groupPosition) {System.out.println("3"+"##############");
super.onGroupCollapsed(groupPosition);
}
@Override
public void onGroupExpanded(int groupPosition) {System.out.println("4"+"##############");
super.onGroupExpanded(groupPosition);
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
// TODO Auto-generated method stub
return false;
}
@Override
public View getGroupView(int position, boolean isExpanded,
View convertView, ViewGroup parent) {
View row = convertView;
SlidingLabelHolder holder = null;
final int p=position;
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new SlidingLabelHolder();
holder.button=(Button)row.findViewById(R.id.sliding_menu);
holder.button.setText(" "+menuLabel[position]);
Drawable img = context.getResources().getDrawable( menuIcon[position] );
img.setBounds( 0, 0, 40, 40 );
holder.button.setCompoundDrawables( img, null, null, null );
holder.button.setId(position);
holder.button.setOnClickListener(this);
System.out.println("5"+"##############");
//row.setTag(0, holder);
//row.setTag(holder);
MenuLabel menuLabel = data[position];
return row;
}
static class SlidingLabelHolder
{
Button button;
}
@Override
public void onClick(View view) {
/*switch(view.getId())
{
case 0 :
{
Intent mi = new Intent(context , DashBoard.class);
context.startActivity(mi);
break;
}
case 1:
{
Intent mi = new Intent(context , CalendarView.class);
context.startActivity(mi);
}
break;
case 2:
Intent t = new Intent(context , PlayerlistActivity.class);
context.startActivity(t);
break;
case 3:
{
Intent mi = new Intent(context , ChosePlayerView.class);
context.startActivity(mi);
break;
}
case 4:
Intent mi = new Intent(context , UserFans.class);
context.startActivity(mi);
break;
case 5:
Intent i = new Intent(context, ChangePassword.class);
//view.getContext().startActivity(i);
break;
case 6:
AlertDialog.Builder a=new Builder(context);
a.setMessage("Do you want to log out from this app");
a.setTitle("Logout ?");
a.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
intent = new Intent(context, LandingActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
});
a.setNegativeButton("cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
a.show();
break;
}*/
}
}
答案 0 :(得分:0)
尝试这样,
ArrayList<GroupHeader> m_list = new ArrayList<GroupHeader> ();
ArrayList<String> sub_items = new ArrayList<String>();
sub_items.add("sub_item1");
sub_items.add("sub_item2");
sub_items.add("sub_item2");
GroupHeader group1 = new GroupHeader("Group1", sub_items);
GroupHeader group1 = new GroupHeader("Group2", sub_items);
GroupHeader group1 = new GroupHeader("Group3", sub_items);
CustomExpandableListAdapter ELA_adapter = new CustomExpandableListAdapter(getActivity(), groupList);
expandableListView.setAdapter(ELA_adapter);
public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
private Context m_context;
private ArrayList<GroupHeader> m_list;
private LayoutInflater m_inflater;
public CustomExpandableListAdapter(Context context, ArrayList<GroupHeader> list){
m_context = context;
m_inflater = LayoutInflater.from(m_context);
m_list = list;
}
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return m_list.get(groupPosition).getSub_items().get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String item = (String) getChild(groupPosition, childPosition);
convertView
-------------------------
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return m_list.get(groupPosition).getSub_items().size();
}
@Override
public Object getGroup(int groupPosition) {
return m_list.get(groupPosition);
}
@Override
public int getGroupCount() {
return m_list.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final GroupHeader group = (GroupHeader) getGroup(groupPosition);
convertView
-------------------------------------------------
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
/* used to make the notifyDataSetChanged() method work */
super.registerDataSetObserver(observer);
}
}
public class GroupHeader {
public GroupHeader(){
}
public GroupHeader(String key, ArrayList<String> value){
this.header = key;
this.sub_items = value;
}
String header = "";
ArrayList<String> sub_items = new ArrayList<String>();
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public ArrayList<String> getSub_items() {
return sub_items;
}
public void setSub_items(ArrayList<String> sub_items) {
this.sub_items = sub_items;
}
}