我面临的一个问题是,当我更改ExpandableListView
子项内部的ImageView
资源时。我正在为不同的父级设置不同的孩子,然后我正在处理其中一个父子项中的按钮单击(在这里我正在groupPosition ==3
中完成所有这些操作(:
过滤器适配器.java
public class FilterAdapter extends BaseExpandableListAdapter {
List<String> groupList;
Map<String,List<String>> childMapList;
List<String> childList;
Context mContext;
FilterListGroupLayoutBinding binding;
FilterbyChildLayoutBinding filterbyChildLayoutBinding;
TransferStatusChildLayoutBinding transferStatusChildLayoutBinding;
SortByDateChildLayoutBinding sortByDateChildLayoutBinding;
private static String childView= "";
private static String groupName="";
private static String childName="";
static int c=1;
TextView ivPickUpTxt;
ImageButton pickUpImage,vouchredImage,cancledImage;
ImageSwitcher bookedonImage;
CheckBox pendingyesCheckBox,pendingNoCheckBox,vehicleAssignCheckBox,vehicleAssignNoCheckbox,driverYesCheckBox,driverNoCheckbox,vehicleDispatchCheckBox;
CheckBox vehicleDispatchNocheckbox,transferCompletedYesCheckBox,transferCompletedNoCheckBox;
CheckBox ivCancleCheckBox,voucheredCheckBox;
RelativeLayout text2Layout,text1Layout;
View convertView1;
TextView bookedonToTxt,bookedOnEdtTxt, pickUpFromEditTxt,pickupDateToText;
EditText supplierConfNo,confEditTxt,passangerNameTxt,pickUpEditTxt ;
Button btm,btm1;
String dateTime;
// FilterFragment filterFragment = new FilterFragment();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
public FilterAdapter(Context context, List<String> groupList, Map<String,List<String>> childMapList) {
this.groupList=groupList;
this.childMapList = childMapList;
this.mContext = context;
}
@Override
public int getGroupCount() {
return groupList.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return groupList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
String s;
s = groupList.get(groupPosition);
childList = childMapList.get(s);
return childList.get(childPosition);
}
@Override
public long getGroupId(int groupPosition ) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View view, ViewGroup viewGroup) {
String headerTitle = (String) getGroup(groupPosition);
if(view == null){
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.filter_list_group_layout, null);
/*binding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.filter_list_group_layout,viewGroup,false);
view = binding.getRoot()*/;
}
ImageView groupIndicatorImage = (ImageView) view.findViewById(R.id.groupIndicatorImage);
ExpandableListView eLV = (ExpandableListView) viewGroup;
eLV.expandGroup(0);
if (isExpanded) {
if(groupPosition==0){
groupIndicatorImage.setVisibility(View.INVISIBLE);
}else {
groupIndicatorImage.setVisibility(View.VISIBLE);
groupIndicatorImage.setBackgroundResource(R.drawable.arrow_down);
}
} else if (!isExpanded) {
if(groupPosition==0){
groupIndicatorImage.setVisibility(View.INVISIBLE);
}else {
groupIndicatorImage.setVisibility(View.VISIBLE);
groupIndicatorImage.setBackgroundResource(R.drawable.filter_arrow);
}
}
TextView groupIndicator = (TextView) view.findViewById(R.id.ivGroupIndicator);
groupIndicator.setText(headerTitle);
/* binding.ivGroupIndicator.setText(headerTitle);*/
return view;
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean b, View convertView, ViewGroup viewGroup) {
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String headerTitle = (String) getGroup(groupPosition);
int childType = getChildType(groupPosition, childPosition);
// String child = getChild(groupPosition, childPosition).toString();
String parent = ((String) getGroup(groupPosition));
// || (int)convertView.getTag()!= childType
if(convertView == null){
if(groupPosition == 0){
convertView = infalInflater.inflate(R.layout.booking_status_child_layout, null);
}
else if(groupPosition == 1){
convertView = infalInflater.inflate(R.layout.filterby_child_layout, null);
}
else if(groupPosition == 2){
convertView = infalInflater.inflate(R.layout.transfer_status_child_layout, null);
}
else if(groupPosition == 3){
convertView = infalInflater.inflate(R.layout.sort_by_date_child_layout, null);
}
}
else{
if(groupPosition == 0){
convertView = infalInflater.inflate(R.layout.booking_status_child_layout, null);
}
else if(groupPosition == 1){
convertView = infalInflater.inflate(R.layout.filterby_child_layout, null);
}
else if(groupPosition == 2){
convertView = infalInflater.inflate(R.layout.transfer_status_child_layout, null);
}
else if(groupPosition == 3){
convertView = infalInflater.inflate(R.layout.sort_by_date_child_layout, null);
/*image.... initialization*/
bookedonImage = (ImageSwitcher) convertView.findViewById(R.id.booedOnImage);
btm = (Button) convertView.findViewById(R.id.btm);
btm1 = (Button) convertView.findViewById(R.id.btm1);
bookedonImage.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView myView = new ImageView(mContext);
myView.setScaleType(ImageView.ScaleType.FIT_CENTER);
return myView;
}
});
btm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bookedonImage.setImageResource(R.drawable.ascending_active);
}
});
btm1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bookedonImage.setImageResource(R.drawable.decending_active);
}
});
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
请帮帮我。
您要更改的视图应在childView方法中声明,如果要在单击按钮时更改ImageSwitcher视图,则可以将其定义为childView方法中的最终变量。
所以孩子视图方法如下所示
public View getChildView(int groupPosition, int childPosition, boolean b, View convertView, ViewGroup viewGroup) {
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String headerTitle = (String) getGroup(groupPosition);
int childType = getChildType(groupPosition, childPosition);
String parent = ((String) getGroup(groupPosition));
if(convertView == null){
switch (childType){
case CHILD_TYPE_1:
convertView = infalInflater.inflate(R.layout.booking_status_child_layout, null);
convertView.setTag(childType);
break;
case CHILD_TYPE_2:
convertView = infalInflater.inflate(R.layout.filterby_child_layout, null);
convertView.setTag(childType);
break;
case CHILD_TYPE_3:
convertView = infalInflater.inflate(R.layout.transfer_status_child_layout, null);
convertView.setTag(childType);
break;
case CHILD_TYPE_4:
convertView = infalInflater.inflate(R.layout.sort_by_date_child_layout, null);
convertView.setTag(childType);
break;
default:
break;
}
}
switch (childType){
case CHILD_TYPE_1:
break;
case CHILD_TYPE_2:
break;
case CHILD_TYPE_3:
break;
case CHILD_TYPE_4:
btm = (Button) convertView.findViewById(R.id.btm);
btm1 = (Button) convertView.findViewById(R.id.btm1);
final ImageSwitcher bookedonImage= (ImageSwitcher) convertView.findViewById(R.id.booedOnImage);
btm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bookedonImage.setImageResource(R.drawable.ascending_active);
}
});
btm1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bookedonImage.setImageResource(R.drawable.decending_active);
}
});
break;
}
return convertView;
}