【问题标题】:Chlid method are not working in BaseExpandable ListAdapter子方法在 BaseExpandableListAdapter 中不起作用
【发布时间】:2017-06-11 07:23:23
【问题描述】:

我正在制作一个闹钟,所以我想在可展开的列表视图中打开单击 group parent 的设置,但单击 group 时没有发生任何事情。此外,像 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>

【问题讨论】:

    标签: android expandablelistadapter


    【解决方案1】:

    所有正在寻找上述问题答案的人。 实际上,当您单击组视图时,子方法有效。 就我而言,我必须添加

    android:descendantFocusability="blocksDescendants"

    此语句在我的 parent_view.xml 的父布局中

    【讨论】:

      猜你喜欢
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多