Chlid方法在BaseExpandable ListAdapter中不起作用

时间:2017-06-11 07:23:23

标签: android expandablelistadapter

我正在制作一个闹钟,所以我想打开可扩展列表视图中单击组父级的设置,但点击组时没有发生任何事情。此外,任何像getchildrencount这样的子方法都不起作用。通过调试了解。 这是我的文件。我的群组视图正常或可见。

适配器文件:

public ExpandableAdapter(Context ctx, ArrayList<ParentBean> parentlist, 
ArrayList<ChildBean> childlist){

    this.ctx = ctx;
    this.parentlist = parentlist;
    this.childlist = childlist;
     map = new HashMap<>();
    for(ParentBean pb : parentlist){
        ;

    map.put(pb,childlist);
    Log.e("childliset",String.valueOf(childlist.size()));
}}
@Override
public int getGroupCount() {
    Log.d("problem","1");
    for(ParentBean b : parentlist){
        Log.e("parentlist",b.toString());
    }

    return parentlist.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    Log.e("problem", "30");
    Log.e("childlist",String.valueOf(childlist.size()));

    return map.get(groupPosition).size();
}

@Override
public Object getGroup(int groupPosition) {
    Log.e("problem2 ", parentlist.get(groupPosition).toString());
    Log.e("groupPosition",String.valueOf(groupPosition));
    return parentlist.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    Log.e("problem3",childlist.get(childPosition).toString());
    return childlist.get(childPosition);
}

@Override
public long getGroupId(int groupPosition) {
    Log.e("problem4",String.valueOf(groupPosition));
    return groupPosition;
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    Log.e("problem4",String.valueOf(childPosition));
    return childPosition;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View 
convertView, ViewGroup parent) {

    ParentBean header = (ParentBean) this.getGroup(groupPosition);

        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) 
 this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.parent_view,null);
        }
        Log.e("Mision2",header.toString());
        TextView alarm_time = 
  (TextView)convertView.findViewById(R.id.alarm_time);
    if(header.getHour()>=12){
        header.setHour(header.getHour()-12);
    }if(header.getHour()<10){
        alarm_time.setText("0"+header.getHour()+" : "+header.getMinute());
    }else{
    alarm_time.setText("0"+header.getHour()+" : "+header.getMinute());}

    TextView date = (TextView)convertView.findViewById(R.id.date);
    if(header.getDate()<10){
        date.setText("0"+header.getMonth()+"-"+header.getDate()+"-
  "+header.getMinute());
    }else {
        date.setText(header.getMonth() + "-" + header.getDate() + "-" + 
 header.getMinute());
    }



    Log.e("mission ", "possible");
    return convertView;
}

 @Override
  public View getChildView(int groupPosition, int childPosition, boolean 
 isLastChild, View convertView, ViewGroup parent) {

    Log.e("mission","impossible");
    ChildBean footer = 
(ChildBean)this.getChild(groupPosition,childPosition);
    if (convertView==null){
        LayoutInflater inflater = 
(LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.child_view,parent,false);

    }







    return convertView;
}

Xml文件子视图:

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent">


  <CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="13dp"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/song_name"
    android:layout_toEndOf="@+id/song_name"
    android:layout_marginLeft="41dp"
    android:layout_marginStart="41dp" />

  <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="16dp"
    android:text=" Song: "
    android:layout_marginLeft="11dp"
    android:layout_marginStart="11dp"
    android:layout_alignBottom="@+id/song_name"
    android:layout_toRightOf="@+id/imageView"
    android:layout_toEndOf="@+id/imageView" />

  <ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginStart="20dp"
    app:srcCompat="@drawable/song_icon"
    android:layout_alignBottom="@+id/textView2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

  <TextView
    android:id="@+id/song_name"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="12dp"
    android:layout_marginStart="12dp"
    android:textSize="16dp"
    android:text="TextView"
    android:layout_alignBaseline="@+id/checkBox"
    android:layout_alignBottom="@+id/checkBox"
    android:layout_toRightOf="@+id/textView2"
    android:layout_toEndOf="@+id/textView2" />

  <TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Vibrate"
    android:textSize="16dp"
    android:layout_alignLeft="@+id/checkBox"
    android:layout_alignStart="@+id/checkBox"
    android:layout_marginLeft="41dp"
    android:layout_marginStart="41dp"
    android:layout_alignTop="@+id/song_name" />

 <ImageButton
    android:id="@+id/imageButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/delete"
    android:layout_marginTop="11dp"
    android:layout_below="@+id/checkBox"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="13dp"
    android:layout_marginStart="13dp" />

  <TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageButton"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="11dp"
    android:textSize="16dp"
    android:layout_toEndOf="@+id/imageButton"
    android:layout_toRightOf="@+id/imageButton"
    android:text="Delete" />
  </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

每个人都在寻找上述问题的答案。 实际上,当您单击组视图时,子方法会起作用。 在我的情况下,我必须添加

机器人:descendantFocusability = “blocksDescendants”

这个语句在我的parent_view.xml的父布局