滚动 ExpandableListView 后计数器的值发生变化

2024-01-08

我有一个 ExpandableListView 项目,在列表项上我有 TextView,其中有两个按钮可以在单击时增加或减少 TextView 中的值。每次我尝试滚动列表时都会出现此问题。如果我增加一项,然后滚动列表,值就会混合(因为 ListView 不断回收其视图),并且我不知道如何修复它。

我已经尝试了在这里找到的许多解决方案,所以是的,这可能是重复的,但我无法用我找到的任何方法解决我的问题。

我的 ExpandableListAdapter.java

    import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;


public class ExpandableListAdapter extends BaseExpandableListAdapter {

public static class ViewHolder {
    TextView childText;
    TextView counterText;
    Button addItemButton;
    Button deleteItemButton;

    int quantity = 0;

}


private Context context;
private List<String> listDataHeader;
private HashMap<String, List<String>> listHashMap;

public ExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listHashMap) {
    this.context = context;
    this.listDataHeader = listDataHeader;
    this.listHashMap = listHashMap;
}

@Override
public int getGroupCount() {
    return listDataHeader.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    return listHashMap.get(listDataHeader.get(groupPosition)).size();
}

@Override
public Object getGroup(int groupPosition) {
    return listDataHeader.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return listHashMap.get(listDataHeader.get(groupPosition)).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 convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);

    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_group, null);

    }
    TextView listHeader = (TextView) convertView.findViewById(R.id.list_header);
    listHeader.setTypeface(null, Typeface.BOLD);
    listHeader.setText(headerTitle);

    return convertView;
}

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

    final ViewHolder viewHolder;

    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_item, null);

        TextView textListChild = (TextView) convertView.findViewById(R.id.list_item_header);
        TextView itemsCounter = (TextView) convertView.findViewById(R.id.items_counter);
        Button addItemButton = (Button) convertView.findViewById(R.id.plus_btn);

        viewHolder = new ViewHolder();
        viewHolder.childText = textListChild;
        viewHolder.counterText = itemsCounter;
        viewHolder.addItemButton = addItemButton;

        convertView.setTag(viewHolder);


    } else {
        viewHolder = (ViewHolder) convertView.getTag();

    }

    final String childText = (String) getChild(groupPosition, childPosition);
    viewHolder.childText.setText(childText);

    viewHolder.addItemButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            //int itemCount = Integer.parseInt((String)viewHolder.counterText.getText());
            //itemCount++;

            viewHolder.quantity++;
            viewHolder.counterText.setText( Integer.toString(viewHolder.quantity));

            PutOrderDrinks.addOrder(childText);

        }
    });


    return convertView;
}

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
       return true;
    } 
}

在 ViewHolder 中存储数量并不是一个好主意。 希望下面的示例有帮助:)

MainActivity.java:

public class MainActivity extends Activity {

Button clearChecks, putOrder;
ExpandableListView expandableListView;
ExpandableListViewAdapter expandableListAdapter;
int lastExpandedPosition = -1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    expandableListView = findViewById(R.id.expandedListView);
    clearChecks = findViewById(R.id.btnClearChecks);
    putOrder = findViewById(R.id.btnPutOrder);

    List<String> listTitle = genGroupList();
    expandableListAdapter = new ExpandableListViewAdapter(this, listTitle, genChildList(listTitle));
    expandableListView.setAdapter(expandableListAdapter);

    expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            if(lastExpandedPosition != -1 && (lastExpandedPosition != groupPosition)){
                expandableListView.collapseGroup(lastExpandedPosition);
            }
            lastExpandedPosition = groupPosition;
        }
    });
    clearChecks.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            expandableListAdapter.clearChecks();
        }
    });
    putOrder.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ArrayList<ChildItemSample> putOrder = expandableListAdapter.getOrderList();
            String msg = "";
            for(int i=0; i<putOrder.size(); i++){
                msg += putOrder.get(i).getName() + ": " + putOrder.get(i).getQty() + "\n";
            }
            Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
        }
    });
}

private ArrayList<String> genGroupList(){
    ArrayList<String> listGroup = new ArrayList<>();
    for(int i=1; i<10; i++){
        listGroup.add("Group: " + i);
    }
    return listGroup;
}

private Map<String, List<ChildItemSample>> genChildList(List<String> header){
    Map<String, List<ChildItemSample>> listChild = new HashMap<>();
    for(int i=0; i<header.size(); i++){
        List<ChildItemSample> testDataList = new ArrayList<>();
        int a = (int)(Math.random()*8);
        for(int j=0; j<a; j++){
            ChildItemSample testItem = new ChildItemSample("Child " + (j + 1), 0);
            testDataList.add(testItem);
        }
        listChild.put(header.get(i), testDataList);
    }
    return listChild;
}
}

ChildItemSample.java:

public class ChildItemSample {
private boolean checked = false;
private String name;
private int qty;

public int getQty() {
    return qty;
}

public void setQty(int qty) {
    this.qty = qty;
}

public boolean isChecked() {
    return checked;
}

public void setChecked(boolean checked) {
    this.checked = checked;
}

public String getName() {
    return name;
}

public ChildItemSample(String name, int qty){
    this.name = name;
    this.qty = qty;
}
}

ExpandableListViewAdapter.java:

public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listGroup;
private Map<String, List<ChildItemSample>> listChild;
private int checkedBoxesCount;
private boolean[] checkedGroup;

public ExpandableListViewAdapter(Context context, List<String> listGroup, Map<String,
        List<ChildItemSample>> listChild) {
    this.context = context;
    this.listGroup = listGroup;
    this.listChild = listChild;
    checkedBoxesCount = 0;
    checkedGroup = new boolean[listGroup.size()];
}

@Override
public int getGroupCount() {
    return listGroup.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    return listChild.get(listGroup.get(groupPosition)).size();
}

@Override
public String getGroup(int groupPosition) {
    return listGroup.get(groupPosition);
}

@Override
public ChildItemSample getChild(int groupPosition, int childPosition) {
    return listChild.get(listGroup.get(groupPosition)).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 b, View view, ViewGroup viewGroup) {
    String itemGroup = getGroup(groupPosition);
    GroupViewHolder groupViewHolder;
    if(view == null){
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.expanded_list_group, null);
        groupViewHolder = new GroupViewHolder();
        groupViewHolder.tvGroup = view.findViewById(R.id.tv_group);
        groupViewHolder.cbGroup = view.findViewById(R.id.cb_group);
        groupViewHolder.cbGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int pos = (int)view.getTag();
                checkedGroup[pos] = !checkedGroup[pos];
                for(ChildItemSample item : listChild.get(listGroup.get(pos))){
                    item.setChecked(checkedGroup[pos]);
                }
                notifyDataSetChanged();
            }
        });
        view.setTag(groupViewHolder);
    }else {
        groupViewHolder = (GroupViewHolder)view.getTag();
    }
    groupViewHolder.tvGroup.setText(String.format("%s (%d)", itemGroup, getChildrenCount(groupPosition)));
    if(checkedGroup[groupPosition]) groupViewHolder.cbGroup.setChecked(true);
    else groupViewHolder.cbGroup.setChecked(false);
    groupViewHolder.cbGroup.setTag(groupPosition);
    return view;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) {
    ChildItemSample expandedListText = getChild(groupPosition,childPosition);
    ChildViewHolder childViewHolder;
    if(view == null){
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.expanded_list_item, null);
        childViewHolder = new ChildViewHolder();
        childViewHolder.tvChild = view.findViewById(R.id.tv_child);
        childViewHolder.cbChild = view.findViewById(R.id.cb_child);
        childViewHolder.tvQty = view.findViewById(R.id.tv_qty);
        childViewHolder.btInc = view.findViewById(R.id.bt_inc);
        childViewHolder.btDec = view.findViewById(R.id.bt_dec);
        childViewHolder.cbChild.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CheckBox cb = (CheckBox) view;
                Pos pos = (Pos) cb.getTag();
                ChildItemSample selectedItem = getChild(pos.group, pos.child);
                selectedItem.setChecked(cb.isChecked());
                if(cb.isChecked()){
                    checkedBoxesCount++;
                    Toast.makeText(context,"Checked value is: " + getChild(pos.group, pos.child).getName(),
                            Toast.LENGTH_SHORT).show();
                }else {
                    checkedBoxesCount--;
                    if(checkedBoxesCount == 0){
                        Toast.makeText(context,"nothing checked",Toast.LENGTH_SHORT).show();
                    }else {
                        Toast.makeText(context,"unchecked",Toast.LENGTH_SHORT).show();
                    }
                }
                notifyDataSetChanged();
            }
        });
        childViewHolder.btInc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Button bt = (Button) view;
                Pos pos = (Pos) bt.getTag();
                ChildItemSample selectedItem = getChild(pos.group, pos.child);
                selectedItem.setQty(selectedItem.getQty() + 1);
                notifyDataSetChanged();
            }
        });
        childViewHolder.btDec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Button bt = (Button) view;
                Pos pos = (Pos) bt.getTag();
                ChildItemSample selectedItem = getChild(pos.group, pos.child);
                if(selectedItem.getQty() > 0) selectedItem.setQty(selectedItem.getQty() - 1);
                notifyDataSetChanged();
            }
        });
    }else {
        childViewHolder = (ChildViewHolder)view.getTag();
    }
    childViewHolder.cbChild.setChecked(expandedListText.isChecked());
    childViewHolder.tvChild.setText(expandedListText.getName() + " :");
    childViewHolder.tvQty.setText("" + expandedListText.getQty());

    childViewHolder.cbChild.setTag(new Pos(groupPosition, childPosition));
    childViewHolder.btInc.setTag(new Pos(groupPosition, childPosition));
    childViewHolder.btDec.setTag(new Pos(groupPosition, childPosition));
    view.setTag(childViewHolder);
    return view;
}

public void clearChecks() {
    for(int i=0; i<checkedGroup.length; i++) checkedGroup[i] = false;
    for(List<ChildItemSample> value : listChild.values()) {
        for (ChildItemSample sample : value) {
            sample.setChecked(false);
        }
    }
    checkedBoxesCount = 0;
    notifyDataSetChanged();
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

private class GroupViewHolder {
    CheckBox cbGroup;
    TextView tvGroup;
}

private class ChildViewHolder {
    CheckBox cbChild;
    TextView tvChild;
    TextView tvQty;
    Button btInc;
    Button btDec;
}

private class Pos {
    int group;
    int child;

    Pos(int group, int child){
        this.group = group;
        this.child = child;
    }
}

public ArrayList<ChildItemSample> getOrderList(){
    ArrayList<ChildItemSample> overallOrder = new ArrayList<>();
    for(int i=0; i<getGroupCount(); i++){
        for(int j=0; j<getChildrenCount(i); j++){
            if(getChild(i,j).getQty() > 0){
                ChildItemSample newOrder = new ChildItemSample(getGroup(i) + ">" +
                        getChild(i, j).getName(), getChild(i, j).getQty());
                overallOrder.add(newOrder);
            }
        }
    }
    return overallOrder;
}
}

活动_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
            <Button
                android:id="@+id/btnClearChecks"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Clear Checks" />
            <Button
                android:id="@+id/btnPutOrder"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Put Order" />
    </LinearLayout>
    <ExpandableListView
        android:id="@+id/expandedListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ExpandableListView>
</LinearLayout>

Expanded_list_group.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants" >
<CheckBox
    android:id="@+id/cb_group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="40dp"
    android:layout_gravity="center_vertical" />
<TextView
    android:id="@+id/tv_group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text"
    android:textSize="30sp" />
</LinearLayout>

Expanded_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
    android:id="@+id/cb_child"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="60dp" />
<TextView
    android:id="@+id/tv_child"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/cb_child"
    android:text="Child: "
    android:textSize="20sp" />
<TextView
    android:id="@+id/tv_qty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/tv_child"
    android:text="0"
    android:textSize="20sp" />
<Button
    android:id="@+id/bt_inc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/bt_dec"
    android:text="+" />
<Button
    android:id="@+id/bt_dec"
    android:layout_marginRight="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:text="-" />
</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

滚动 ExpandableListView 后计数器的值发生变化 的相关文章

  • 在android中,将相机预览流到视图上

    我想将 Android 相机的相机预览流式传输到视图上 目的是随后使用 onDraw 将各种内容添加到视图中 我不需要随时实际捕捉图像 它不必是最高质量或每秒最大数量的帧 有谁知道如何做到这一点 将其添加到您的 xml 中
  • 如何通过注解用try-catch包装方法?

    如果应该在方法调用中忽略异常 则可以编写以下内容 public void addEntryIfPresent String key Dto dto try Map
  • Android 中的 OpenGL 缩小

    我正在使用 3D 对象并渲染它并通过扩展 GLSurfaceView 实现渲染器来显示它 问题是如何通过捏合和捏合进行缩小 下面是我的班级 package com example objLoader import java nio Byte
  • Java、Spring:使用 Mockito 测试 DAO 的 DataAccessException

    我正在尝试增加测试覆盖率 所以我想知道 您将如何测试 DAO 中抛出的 DataAccessExceptions 例如在一个简单的 findAll 方法中 该方法仅返回数据源中的所有数据 就我而言 我使用 Spring JdbcTempla
  • 用于缓存的 Servlet 过滤器

    我正在创建一个用于缓存的 servlet 过滤器 这个想法是将响应主体缓存到memcached 响应正文由以下方式生成 结果是一个字符串 response getWriter print result 我的问题是 由于响应正文将不加修改地放
  • 安卓。 CalendarView...一次仅显示一个月的日历

    我正在使用 CalendarView 其中我想一次仅查看一个月的日历并滚动查看下个月 但 CalendarView 一次显示所有月份 下面是我的代码
  • 如何从日期中删除毫秒、秒、分钟和小时[重复]

    这个问题在这里已经有答案了 我遇到了一个问题 我想比较两个日期 然而 我只想比较年 月 日 这就是我能想到的 private Date trim Date date Calendar calendar Calendar getInstanc
  • Java - 从 XML 文件读取注释

    我必须从 XML 文件中提取注释 我找不到使用 JDOM 或其他东西来让它们使用的方法 目前我使用 Regex 和 FileReader 但我不认为这是正确的方法 您可以使用 JDOM 之类的东西从 XML 文件中获取注释吗 或者它仅限于元
  • Android模拟器中的网络访问

    我试图通过我的 Android 应用程序访问互联网 但我既成功又失败 我在构建应用程序时启动模拟器 并且应用程序安装得很好 我可以使用浏览器访问互联网 但是 当我尝试这个小代码片段时 InetAddress inet try inet In
  • Android SearchView 在启动时隐藏键盘

    我有一个小问题正在尝试解决 当我打开应用程序时 键盘会显示输入搜索视图的查询 不过 我只想在单击搜索视图时显示键盘 我该如何解决 Thanks 这对我有用 用于隐藏焦点的代码 searchView SearchView view findV
  • 使用Java绘制维恩图

    我正在尝试根据给定的布尔方程绘制维恩图 例如 a AND b AND c我想在 Android 手机上执行此操作 因此我需要找到一种使用 Java 来执行此操作的方法 我找到了一个完美的小部件 它可以完成我在这方面寻找的一切布尔代数计算器
  • 当目标小于 Android O 时,如何在 Android O 上创建快捷方式?

    背景 Android O 对快捷方式的工作方式进行了各种更改 https developer android com preview behavior changes html as https developer android com
  • 离子初始加载时间

    我正在使用 Ionic 构建一个简单的应用程序 但我的应用程序在冷启动时的初始加载时间方面存在性能问题 这是我所做的 collection repeat 代替带有 track by 的 ng repeat 原生滚动 overflow scr
  • fs-extra:源和目标不能相同。 (科尔多瓦)

    我在使用 cordova 构建时遇到错误 Error Source and destination must not be the same 构建系统 Ionic ionic cli 4 10 1 ionic framework ionic
  • ECDH使用Android KeyStore生成私钥

    我正在尝试使用 Android KeyStore Provider 生成的私有文件在 Android 中实现 ECDH public byte ecdh PublicKey otherPubKey throws Exception try
  • Android-dispatchTouchEvent 给了我一个 StackOverflowError

    这里我有一个带有 setOnTouchListener 的 ViewFlipper 它工作得很好 然后我膨胀 ReLayNewsItem 然后将其添加到 ViewFlipper 现在我希望 WebView web 监听触摸事件并将它们传递给
  • 丢失应用程序的密钥库文件(但已启用 Google Play 应用程序签名)

    我已经失去了原来的keystore用于签署我的应用程序的文件 我的应用启用了 Google Play 应用签名 如果我联系 Google 支持人员 是否可以重置密钥 以便我可以继续上传到此包 我希望我可以做到这一点 因为应用程序签名已启用
  • 记录类名、方法名和行号的性能影响

    我正在我的 java 应用程序中实现日志记录 以便我可以调试应用程序投入生产后可能出现的潜在问题 考虑到在这种情况下 人们不会奢侈地使用 IDE 开发工具 以调试模式运行事物或单步执行完整代码 因此在每条消息中记录类名 方法名和行号将非常有
  • 使用 JFreeChart 为两个系列设置不同的 y 轴

    我正在使用 JFreeChart 使用折线图绘制两个数据系列 XYSeries 复杂的因素是 其中一个数据系列的 y 值通常远高于第二个数据系列的 y 值 假设第一个系列的 y 值约为数百万数量级 而第二个数据系列的 y 值约为数百万数量级
  • 基于 Spring Boot 的测试中的上下文层次结构

    我的 Spring Boot 应用程序是这样启动的 new SpringApplicationBuilder sources ParentCtxConfig class child ChildFirstCtxConfig class sib

随机推荐

  • C# Windows 窗体用户控件控件设计器支持

    我正在寻找的是对用户控件内的控件的相同类型的设计器支持 即 调整用户控件内的文本框大小 移动标签将用户控件放置到表单上之后 我能做的事 创建一个用户控件 使用设计器向其添加控件 创建一个新的窗口窗体应用程序 将用户控件添加到工具箱 将控件拖
  • JQuery 在该位置插入表格行

    我一直在研究一种能够向 html 表插入行的解决方案 这非常棘手 我发现了一些有用的东西 但仅适用于第一个 插入 我不知道我做错了什么 我有一个包含 3 列的基本表格 每个表格都有一个按钮 允许在两行之间插入一行 我在这个网站上搜索了一个解
  • 如何让 .env 预提交 + mypy + django-stubs

    我尝试在提交之前配置启动 mypy django stubs 检查 我使用预提交 当我尝试提交时 出现错误django core exceptions ImproperlyConfigured 设置 POSTGRES DB 环境变量 该变量
  • java.sql 中的日期时间等效项? (有 java.sql.datetime 吗?)

    到目前为止 我还没有找到明确的答案 我想知道使用PreparedStatement 的SQL 类型DATETIME 和java 类型的等价物是什么 我已经发现 http www java2s com Code Java Database S
  • Shell 脚本中的 exec ${PERL-perl} -Sx $0 ${1+"$@"} 是什么意思?

    我的任务是将包含 Shell 脚本 Perl 代码的 shell 脚本转换为 Python 我设法将 Perl 代码转换为 Python 但是有这个shell脚本语句我不明白 usr bin sh exec PERL perl Sx 0 1
  • 没有元素时流的特殊行为

    我如何用 java 8 Streams API 表达这一点 我想表演itemConsumer对于流的每个项目 如果有 没有我想要执行的项目emptyAction 当然我可以写这样的东西 Consumer itemConsumer Syste
  • 没有画布的 HTML5 getImageData [重复]

    这个问题在这里已经有答案了 有没有办法在没有画布的情况下使用图像的 getImageData 我想要获取图像鼠标位置处的像素颜色 不 你不能 但是获取 imageData 可以使用内存中的画布来完成 这既快速又简单 var canvas d
  • Powershell ISE 在使用 GitLab Runner 时抛出 RemoteException

    I am trying to stop GitlabRunner windows service using powershell When I execute the command in elevated powershell prom
  • 如何使用可视化代码编辑器在 chrome 上运行 flutter

    如何在 Chrome 上运行 flutter 应用程序 我已经安装了颤振套件并运行 颤振通道测试版 颤振升级 并在 Visual Studio Code 上安装扩展 就像与flutter mobile create flutter laun
  • Python内存模型和指针

    我正在学习 Python 并对 Python 的内存模型感到困惑 变量包含它所引用的对象的内存地址 这听起来就像 Python 变量实际上是指针 因为它们只直接包含实际对象实例的内存地址 那么当我调用变量名时Python会做什么呢 Pyth
  • 在 Python 中将频谱图存储为图像

    我想将音频的 STFT 频谱图存储为图像 下面的代码向我显示了一个频谱图作为输出 但是当保存为图像时 我得到了不同的图像 import numpy as np import matplotlib pyplot as plt import p
  • UICollectionViewCell 中的标签文本未更新

    我正在尝试更改 a 的文本UILabel in a UICollectionViewCell之后UICollectionViewCell已加载 当点击button 但屏幕上的标签不会更新 控制台显示标签的文本属性已更新 但标签似乎并未使用新
  • 对于没有正文的 4xx 错误,Content-Type 应该是什么?

    考虑一个获得以下响应的 HTTP 请求 405 Method Not Allowed Content Length 0 像这样的内容类型应该是什么 设置为无 Not set Set to text plain or text html 您没
  • Lucene.net 2.9.2 排序(排序不起作用)

    我在 NET 中对 lucene net 索引进行排序时遇到问题 我尝试了 stackoverflow 上的几乎所有解决方案并寻找谷歌答案 我正在使用 Lucene NET 2 9 2 和 ASP NET 2 0 我想像在 sql 中一样对
  • 如何在适用于 iOS 的谷歌地图 sdk 中设置带有位置的中心地图视图

    如何在 iOS 版谷歌地图 sdk 中设置中心地图视图和位置 使用mapkit 我们可以执行setCenter Location 如何使用适用于 iOS 的 google 地图 sdk 执行此操作 使用 GMSCameraPosition
  • 从种子点生成特定半径内的随机地理坐标

    我使用以下函数从种子点生成指定半径内的随机地理坐标 function randomGeo center radius var y0 center latitude var x0 center longitude var rd radius
  • 如何在 Java 中挂载 Windows 驱动器?

    我们正在使用一些通过字母 例如 f 访问共享驱动器的遗留代码 使用 UNC 表示法不是一个选项 我们的 Java 包装应用程序将作为服务运行 作为第一步 我想在代码中显式映射驱动器 有人这样做过吗 考虑执行映射网络驱动器的 DOS 命令 如
  • CPU-GPU并行编程(Python)

    有没有一种方法可以在 CPU 和 GPU 上同时运行函数 使用 Python 我已经在使用 Numba 对 GPU 上的计算密集型函数进行线程级调度 但我现在还需要在 CPU GPU 之间添加并行性 一旦我们确保 GPU 共享内存拥有开始处
  • 使用 StringBuilder 随机化文本框中的行顺序

    我试图随机化最终结果 这里的想法是让文本框行执行一些代码 然后将其导出到 textbox2 代码正在工作 但我想在导出到 textbox2 时随机化行顺序 Dim newr As New StringBuilder For Each lin
  • 滚动 ExpandableListView 后计数器的值发生变化

    我有一个 ExpandableListView 项目 在列表项上我有 TextView 其中有两个按钮可以在单击时增加或减少 TextView 中的值 每次我尝试滚动列表时都会出现此问题 如果我增加一项 然后滚动列表 值就会混合 因为 Li