나는 이런 식으로 뭔가를 할 줄 알았 사용자 정의 어댑터 (이러한 확장 baseexpandableadapter 클래스) 활용하여 확장 가능한 목록보기를 만드는 것입니다. 그런 다음 그룹 뷰 및 하위 뷰에 대해 다른 뷰를 전개하거나 생성 할 수 있습니다. 이것은 (확장 목록보기 정기적 인 활동 대)이 확장 listactivity를 사용하는 경우 당신이 그것을 설정하는 방법의 예입니다
public class ExpandableList1 extends ExpandableListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up our adapter
ExpandableListAdapter mAdapter = new MyExpandableListAdapter(this);
setListAdapter(mAdapter);
}
// The custom adapter part
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = { "Task1", "Task2", "Task3", "Task4"};
private String[][] children = {
{ "Task Description", "Task time limit date" },
{ "Task Description", "Task time limit date" },
{ "Task Description", "Task time limit date" },
{ "Task Description", "Task time limit date" }
};
public MyExpandableListAdapter(Context context) {
super();
this.context = context;
}
private Context context;
static class ViewHolder {
TextView text;
CheckBox checkbox;
}
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 View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
return convertView;
}
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) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = viewInflater.inflate(R.layout.mtopics_groupview, parent, false);
holder = new ViewHolder();
holder.text = (TextView)convertView.findViewById(R.id.mtopicsgrouptv);
holder.checkbox = (CheckBox)convertView.findViewById(R.id.cb_group);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getGroup(groupPosition).toString());
return convertView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
당신은 프로그래밍 방식으로 또는에 그룹 뷰와 아이 뷰를 만들 수있는 능력을 가지고 당신은 XML에서 이것을 팽창시킬 수 있습니다. 필자의 예제에서는 좀 더 복잡한보기가 훨씬 쉬워 짐에 따라 XML로부터 그룹 뷰를 위해 너무 팽창했습니다. 그 패턴은 두 줄의 코드를 사용하는 둥근 방법처럼 보이지만,보기의 성능을 대폭 향상시키는 데 도움이 될 것입니다. 자세한 내용은 http://www.youtube.com/watch?v=wDBM6wVEO70에서 확인할 수 있습니다. 현재 XML은 매우 단순하며 텍스트보기와 체크 박스입니다.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/cb_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:checked="true"
android:focusable="false" />
<TextView
android:id="@+id/mtopicsgrouptv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:focusable="false"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
내가하지 않았다 : (작은 힌트 groupviews의 체크 박스는 "포커스"가 false로 설정해야합니다 직접 인접한 그룹보기의 지표가 될 수없는, 또는 그룹보기 확장 할 수 없습니다) 하위보기를 수행합니다. 그러나이를 수행하려는 작업에 따라 그룹보기 후에 모델을 작성할 수 있습니다. 당신은 그곳에 텍스트 뷰를 넣고 자식 위치를 기반으로 텍스트를 설정할 수 있습니다. 하지만 이제는으로 경고해야합니다. 클릭하면 즉시 확인란 상태가 엉망이 될 것입니다. 때때로 수 표가 움직이거나 사라지거나 전혀 작동하지 않을 것입니다. 내가 왜 당신에게 말할 수 있는지 알고 싶다면, 지금은 해결책을 게시 할 것입니다. arraylist 또는 map이나 체크 박스 상태를 유지하기위한 어떤 것이 든 설정해야한다. 여기 내 getGroupView 부분에서 어떻게 할 것입니다.
// make the list
ArrayList<Boolean> group_check_states = new ArrayList<Boolean> (groups.length);
for(int i = 0; i < groups.length; i++) {
group_check_states.add(true);
}
// load the checkstates
if ((group_check_states.get(groupPosition)) == true) {
holder.checkbox.setChecked(true);
} else {
holder.checkbox.setChecked(false);
}
// save the checkstates
holder.checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (holder.checkbox.isChecked()) {
group_check_states.set(groupPosition, true);
} else {
group_check_states.set(groupPosition, false);
}
}
});
체크 박스 작업 코드도 입력 할 수 있습니다. 이제 어댑터가 그 부분을 보았지만 의도 한대로 너무 간단 할 수도 있습니다. 경보 대화 상자에 입력 된 내용을 기반으로 작업을 동적으로 설정할 수 있기를 원합니다. 이 경우, 단순히 내가 사용했던 배열 (그룹과 자식)을 사용하고 싶지 않을 것입니다. arraylist 또는 다른 유형의 목록을로드하여 동적으로 추가하고 제거 할 수있는 목록을로드하는 것이 좋습니다. 경고 대화 상자로 수정하십시오.
도움이 되었기를 바랍니다.하지만 앞으로 더 많은 문제가있을 것으로 확신합니다. 일이 생기면 그냥 훌라.