확장 리스트 뷰에서 부모 그룹 클릭시 자식 리스트가 나오잖아요
그런데 이때 자식 리스트를 누르며 또 자식 밑의 자식 리스트가 나오게 하고 싶습니다
이게 가능한가요??
부모1
자식1
자식1-1
자식1-2
자식1-3
자식2
자식3
부모2
부모3
이렇게 하고싶은데 어디를 건들어야될지 모르겠네요...
책의 소스는 이렇게 되있습니다
package com.androidside.expandablelistdemoa1;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
public class Main extends Activity implements
ExpandableListView.OnGroupClickListener,
ExpandableListView.OnChildClickListener{
ExpandableListView listView;
String[] groups = { "Number", "Alphabet" };
String[][] childs = { { "1", "2", "3", "4", "5" },
{ "A", "B", "C", "D", "E" }};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ExpandableListAdapter listAdapter = new MyExpandableListAdapter();
listView = (ExpandableListView) findViewById(R.id.listview);
listView.setAdapter(listAdapter);
listView.setOnGroupClickListener(this);
listView.setOnChildClickListener(this);
}
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
public Object getChild(int groupPosition, int childPosition) {
return childs[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return childs[groupPosition].length;
}
public TextView getGenericView() {
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(Main.this);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
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());
// 그룹 표시 아이콘 존재 여부
listView.setGroupIndicator(null);
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Toast.makeText(this, "Group : " + groups[groupPosition], Toast.LENGTH_SHORT).show();
return false;
}
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(this, "Child : " + childs[groupPosition][childPosition], Toast.LENGTH_SHORT).show();
return true;
}
}
커스텀하게 만드셔야 합니다.
이미 커스텀 뷰를 만든게 있습니다.
android tree view로 검색해 보세요.