마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Child....ExpandableListAdapter

0 추천
package com.example.busankok;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.SimpleExpandableListAdapter;
import android.widget.Toast;
 
public class CooklistActivity extends Activity implements OnChildClickListener {
 
ExpandableListView mList;
String[] arProv = new String[] { "동서울종합터미널", "서울고속버스터미널", "아이고", "이걸",
"우짜냐" };
String[][] arCity = new String[][] { // 서울 고속버스터미녈은 강남
{ "부산종합버스터미널" }, { "부산서부버스터미널", "부산종합버스터미널" }, { "1", "2", "3", "4" },
{ "5", "6", "7", "8" }, { "9", "0" }, };
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cooklist);
mList = (ExpandableListView) findViewById(R.id.list);
List<Map<String, String>> provData = new ArrayList<Map<String, String>>();
 
List<List<Map<String, String>>> cityData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < arProv.length; i++) {
Map<String, String> Prov = new HashMap<String, String>();
Prov.put("prov", arProv[i]);
provData.add(Prov);
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < arCity[i].length; j++) {
Map<String, String> City = new HashMap<String, String>();
 
City.put("city", arCity[i][j]);
children.add(City);
 
}
cityData.add(children);
 
ExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this, provData,
android.R.layout.simple_expandable_list_item_1,
new String[] { "prov" }, new int[] { android.R.id.text1 },
cityData, android.R.layout.simple_expandable_list_item_1,
new String[] { "city" }, new int[] { android.R.id.text1 }
 
);
 
mList.setAdapter(adapter);
 
}
 
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.cooklist, menu);
return true;
}
 
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
int grposition = groupPosition;
int chposition = childPosition;
long ids = id;
 
 
if (grposition == 0) {
switch (chposition) {
 
case 0:
 
Intent it = new Intent(this,CookActivity.class);
startActivity(it);
break;
 
case 1:
 
Intent it2 = new Intent(this,CookActivity.class);
startActivity(it2);
break;
 
 
}
}
 
return true;
}
 
}
 
 
자식인 Child를 클릭시 intent 화면 전환이 이루어 지게 하고 싶은데
처음 써보는 녀석이라 힘드네요... 몇일째 잡고있는지;;
고수님들의 도움이 간절히 필요 합니다.

 

리뷰즈 (480 포인트) 님이 2015년 4월 6일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...