小编Dla*_*ash的帖子

在ChildView上单独选择CheckBox的Android ExpandableListView

朋友们,

我正在尝试编写一个ExpandableListView,它使用ChildView上的单选复选框.我无法理解如何在ExpandableListView的OnChildClickListener()中将其他CheckBox设置为"false".这是我的代码:

 ExpListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
                if (cb.isChecked()) {           

                } else {
                    cb.setChecked(true);
                    //Here somehow I must set all other checkboxes to false.
                            //Is it possible?
                }
                return false;
            }
   });
Run Code Online (Sandbox Code Playgroud)

这是xml的ChildView:

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

  <TextView
     android:id="@+id/textChild"
     android:layout_width="wrap_content"
     android:layout_height="40dp"
     android:layout_marginLeft="20dp"
     android:layout_marginTop="20dp"
     android:textColor="@android:color/white"
     android:layout_weight="1"
     />

<CheckBox android:id="@+id/checkbox" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:focusable="false" 
      android:clickable="false" 
      android:layout_gravity="right" 
      android:visibility="visible"
/> 

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

checkbox android expandablelistview

5
推荐指数
1
解决办法
2829
查看次数

从QByteArray转换为double数组

我有一个数组double:

QVector<double> Y(count);
Run Code Online (Sandbox Code Playgroud)

我需要将其打包QByteArray以通过以太网发送.

所以我做到了.这不是太难:

QByteArray line;
line.clear();
line.append(QByteArray::fromRawData(reinterpret_cast<const char*>(Y.data()),
count*sizeof(double)));
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码从QByteArray recv以下位置解压缩数据:

QVector<double> data((line.size())/sizeof(double));
QByteArray dou(sizeof(double),0x0);
for(int i = 0; i<data.count(); i++){
    dou = recv.mid(i*sizeof(double),sizeof(double));
    data[i] = *reinterpret_cast<const double*>(dou.data());
    dou.clear();
}
Run Code Online (Sandbox Code Playgroud)

但我不喜欢它.我想找出优雅的方式从解压QByteArrayQVector<double> 你能帮助我吗?

c++ arrays qt reinterpret-cast qbytearray

4
推荐指数
1
解决办法
4331
查看次数