안녕하세요!
expandable list 를 이용해서 메뉴를 구성하고, 그 밑에 child 를 case로 나눠서 intent 를 연결하고.
어떤것은 Toast 를 이용하여 구현하려 합니다
문제는 parent 0 child 0 일때, parent 0 child 1 ...
이런식으로 구분을 해 줘야 되는데,
child 가 0 이면 무조건 toast 가 뜹니다.
뭐가 잘못된 걸까요?
소스는 다음과 같습니다. 더운데 건강 조심 하세요!!
public class IntroClair extends ExpandableListActivity {
ExpandableListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {
Intent i = new Intent(this, ImageSwitcher1.class);
startActivity(i);
return false;
};
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.setHeaderTitle("http://www.gfshop.kr");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
String title = ((TextView) info.targetView).getText().toString();
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos, Toast.LENGTH_SHORT).show();
return true;
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = { "끌레어 주드는...", "주요 브랜드", "주요 품목", "유통망","회사연혁" };
private String[][] children = {
{ "설립배경"},
{ "GIORGIO FERRI", "VOLARE", "MIFFY", "CLAIRJUDE", "VEOU", "METROCITY" },
{ "주얼리,액세서리", "우산,양산,장갑","기타 용품" },
{ "온라인", "오프라인", "특판" },
{ "회사 연혁" }
};
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(IntroClair.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
switch (groupPosition){
case 0:
switch (childPosition) {
case 0:
startActivity(new Intent(IntroClair.this, IntroClair_1.class));
default:
break;
}
case 1:
switch (childPosition) {
case 0:
break;
default:
break;
}
case 2:
switch (childPosition){
case 0:
final Toast t = Toast.makeText(IntroClair.this, "조르지오페리(GIORGIO FERRI)," +
"볼라레(VOLARE),미피(MIFFY),보우(VEOU)", Toast.LENGTH_SHORT);
t.show();
break;
case 1:
final Toast t2 = Toast.makeText(IntroClair.this, "메트로시티(METROCITY),앙드레김(Andre Kim)." +
"미피(MIFFY),키도레이블(Kido Rable)",Toast.LENGTH_SHORT);
t2.show();
break;
case 2:
final Toast t3 = Toast.makeText(IntroClair.this, "미피(MIFFY), 다나한(소망화장품), SKII등"
,Toast.LENGTH_SHORT);
t3.show();
break;
default:
break;
}
case 3:
switch (childPosition){
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
return false;
}
public boolean hasStableIds() {
return true;
}
}
}
case 0:
switch (childPosition) {
case 0:
startActivity(new Intent(IntroClair.this, IntroClair_1.class));
default:
break;
}
break; //이거 추가해야 하지 않을까요?