Bạn nên có một lớp có tất cả các phương pháp thực hiện của ExpandableListAdapter
cũng như ChildItemsInfo
và một lớp học GroupItemsInfo
, với MainActivity
để người nghe nhấp chuột nhóm các mục và con cái của họ
... bây giờ để cụ thể hơn ...
Bạn có thể đặt này trong vòng getGroupView()
đó là bên MyExpandableListAdapter
lớp
View ind = convertView.findViewById(R.id.group_indicator);
View ind2 = convertView.findViewById(R.id.group_indicator2);
if (ind != null)
{
ImageView indicator = (ImageView) ind;
if (getChildrenCount(groupPosition) == 0)
{
indicator.setVisibility(View.INVISIBLE);
}
else
{
indicator.setVisibility(View.VISIBLE);
int stateSetIndex = (isExpanded ? 1 : 0);
/*toggles down button to change upwards when list has expanded*/
if(stateSetIndex == 1){
ind.setVisibility(View.INVISIBLE);
ind2.setVisibility(View.VISIBLE);
Drawable drawable = indicator.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
else if(stateSetIndex == 0){
ind.setVisibility(View.VISIBLE);
ind2.setVisibility(View.INVISIBLE);
Drawable drawable = indicator.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
}
}
... và như đối với quan điểm bố trí, đây là cách group_items tôi. xml dường như là đủ
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/group_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textSize="15sp"
android:textStyle="bold"/>
<ImageView
android:id="@+id/group_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/arrow_down_float"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingTop="20dp"/>
<ImageView
android:id="@+id/group_indicator2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/arrow_up_float"
android:layout_alignParentRight="true"
android:visibility="gone"
android:paddingRight="20dp"
android:paddingTop="20dp"/>
Không rõ ràng ?, bình luận bất cứ khi nào
Nguồn
2017-02-28 20:42:03
'groupItem' và' childItem' là gì. NewAdapter là gì và nó xử lý 'groupItem' và' childItem' như thế nào để làm cho một số mục có thể mở rộng? Câu trả lời của bạn chưa hoàn thành. –
groupItem là một mảng chứa Strings cho từng tùy chọn Nhóm. "TopView 2" ở trên đồ họa. childItem là một ma trận/băm có chứa một danh sách các mục được thả xuống sau khi chọn từng mục trong nhóm. NewAdapter gán các giá trị của các bộ dữ liệu groupItem và childItem cho các khung nhìn khi nó thổi phồng chủ của mỗi mục. – AlleyOOP