Android expandablelistview数据绑定的问题

kycp1 发布于 2018/04/26 17:55
阅读 238
收藏 0

我使用runOnUiThread来执行异步任务AsyncTask,并在AsyncTask中更新expandablelistview,为什么expandablelistview只显示了一条getGroupView?点击它的时候没有调用getChildView,这是什么情况,求大神解答~

源码:1、用runOnUiThread来执行异步任务AsyncTask

BackgroundTask.mTimerTaskHandling = new TimerTask() {
   @Override
   public void run() {
      ((Activity) context).runOnUiThread(new Runnable() {
         @Override
         public void run() {
            new DosUpdater(context, device.getDevId(), null,listItemView.expandableListView).execute();
         }
      });
   }
};

2、在AsyncTask中更新expandablelistview

@Override
protected void onPostExecute(Void param) {
    if (jExpandableLVS != null){  //jExpandableLVS 数据库源JSON格式
       expandableListView.setAdapter(new DosClientExpandableAdapter(jExpandableLVS));
    }
}

3、expandablelistview数据绑定

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
//        item1();
        if (convertView == null){
            convertView = View.inflate(MainContext.INSTANCE.getContext(),R.layout.dos_client_group,null);
        }
        TextView tv_group = convertView.findViewById(R.id.tv_group);
        tv_group.setText(group[groupPosition]);
        TextView tv_count = convertView.findViewById(R.id.count_data);
        tv_count.setText("2511");
        TextView tv_rx = convertView.findViewById(R.id.rx_data);
        tv_rx.setText("43211");
        TextView tv_tx = convertView.findViewById(R.id.tx_data);
        tv_tx.setText("6542");
        notifyDataSetChanged();
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = View.inflate(MainContext.INSTANCE.getContext(),R.layout.dos_client_child,null);
        }
        TextView tv_group = convertView.findViewById(R.id.tv_group);
        tv_group.setText(childs[groupPosition][childPosition]);
        notifyDataSetChanged();
        return convertView;
    }

4、xml页面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <RelativeLayout
        android:id="@+id/devicelayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:paddingBottom="20dp"
        android:paddingLeft="30dp"
        android:paddingRight="10dp"
        android:paddingTop="20dp">

        <ImageView
            android:id="@+id/deviceicon"
            android:layout_width="50dp"
            android:layout_height="45dp"
            android:layout_centerVertical="true" />

        <RelativeLayout
            android:id="@+id/rightlayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            android:layout_toRightOf="@id/deviceicon">

            <ImageButton
                android:id="@+id/stop"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/stop" />

            <TextView
                android:id="@+id/commit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/stop"
                android:gravity="left"
                android:singleLine="true"
                android:textColor="@android:color/white"
                android:textSize="24sp" />

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/commit">

                <TextView
                    android:id="@+id/status"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:singleLine="true"
                    android:textSize="16sp" />
            </RelativeLayout>
        </RelativeLayout>

    </RelativeLayout>
    <TextView 
        android:id="@+id/moreview"
        android:layout_below="@id/devicelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:textSize="20sp"
        android:singleLine="true"

        android:gravity="center"
        android:paddingLeft="8dp"
        android:paddingRight="20dp"
        android:textColor="#ffffff"
        />
    <CheckBox
        android:id="@+id/choose"
        android:layout_width="40dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:background="@android:color/transparent"
        android:visibility="gone"

        >
    </CheckBox>

    <ExpandableListView
        android:id="@+id/clientExpandableLV"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="130dp">

    </ExpandableListView>
    
 </RelativeLayout>
加载中
返回顶部
顶部